PianoComposer 2.8.3

PianoComposer 2.8.3

许可证 Apache-2.0
发布日期上次发布2024 年 8 月

Piano.ioPiano.ioSergey StenshinSergey BayborodovAlexey Troshkov 维护。



 
依赖
PianoConsents~> 1.0.6
PianoCommon~> 2.8.3
 

  • Piano Inc.

Piano SDK for iOS

Piano SDK 包含用 Swift 编写的动态框架。

Version Platform License

  • PianoOAuth: 成分,用于使用用户提供者 Piano ID 和 Piano Accounts 进行身份验证。框架可用于开发 iOS 应用程序,支持 Objective-c 和 Swift。

Version Platform License

此文档详细说明了将 Piano SDK 集成到您的 iOS 应用程序的过程。如果您有任何疑问,请随时通过电子邮件发送给我们:[email protected]

需求

  • iOS 9.0+
  • Xcode 12.0
  • Swift 5.1

安装

<

CocoaPods

将以下行添加到您的 Podfile

use_frameworks!

pod 'PianoComposer', '~>2.4.1'
pod 'PianoOAuth', '~>2.4.1'

然后运行 pod install。有关CocoaPods的安装和使用详情,请访问官方网站

使用PianoComposer

导入
// swift
import PianoComposer
// objective-c
@import PianoComposer;
端点
PianoEndpoint.production // Production endpoint
PianoEndpoint.productionAustralia // Production endpoint for Australia region
PianoEndpoint.productionAsiaPacific // Production endpoint for Asia/Pacific region
PianoEndpoint.sandbox // Sandbox endpoint
初始化
PianoComposer(aid: "<PUBLISHER_AID>") // Production endpoint is used by default (PianoEndpoint.production)
// or
PianoComposer(aid: "<PUBLISHER_AID>", endpoint: PianoEndpoint.sandbox)
使用
var composer = PianoComposer(aid: "<PUBLISHER_AID>")
.delegate(self) // conform PianoComposerDelegate protocol
.tag("tag1") // add single tag
.tag("tag2") // add single tag
.tags(["tag3", "tag4"]) //add array of tags
.zoneId("Zone1") // set zone
.referrer("http://sitename.com") // set referrer
.url("http://pubsite.com/page1") // set url
.customVariable(name: "customId", value: "1") // set custom variable
.userToken("userToken") // set user token
执行作曲器
composer.execute()
钢琴作曲器代理协议
// Client actions
optional func composerExecutionCompleted(composer: PianoComposer)

// Composer actions from server 
optional func showLogin(composer: PianoComposer, event: XpEvent, params: ShowLoginEventParams?)
optional func showTemplate(composer: PianoComposer, event: XpEvent, params: ShowTemplateEventParams?)
optional func setResponseVariable(composer: PianoComposer, event: XpEvent, params: SetResponseVariableParams?)
optional func nonSite(composer: PianoComposer, event: XpEvent)
optional func userSegmentTrue(composer: PianoComposer, event: XpEvent)
optional func userSegmentFalse(composer: PianoComposer, event: XpEvent)    
optional func meterActive(composer: PianoComposer, event: XpEvent, params: PageViewMeterEventParams?)
optional func meterExpired(composer: PianoComposer, event: XpEvent, params: PageViewMeterEventParams?)    
optional func experienceExecute(composer: PianoComposer, event: XpEvent, params: ExperienceExecuteEventParams?)
显示模板

我们建议在移动模板中使用该标签,以确保在iOS设备上正确显示

<meta name="viewport" content="width=device-width, initial-scale=1">

PianoOAuth 使用

导入

// swift
import PianoOAuth
// objective-c
@import PianoOAuth;

钢琴账户用户提供者

使用
let vc = PianoOAuthPopupViewController(aid: "<PUBLISHER_AID>") // for piano accounts user provider
...
vc.delegate = someDelegate // conform PianoOAuthDelegate protocol
vc.signUpEnabled = true // makes "sign up" button enabled (default: false)
vc.widgetType = .login // widget type (possible values: ".login", ".register")
vc.showPopup()
钢琴OAuthDelegate 协议
func loginSucceeded(accessToken: String)
func loginCancelled() 
截图

iPhone example

iPad example

钢琴ID用户提供商

钢琴ID

PianoID需要在一个项目中添加自定义URL方案。添加方法:打开项目配置文件,从目标(TARGETS)部分选择您应用的选项,然后选择“信息”标签,展开“URL Types”部分。

io.piano.id.<PUBLISHER_AID_LOWERCASE> 设置为URL方案。例如:请参阅以下链接中的示例:[Url scheme example](./Images/url_types.png)

要启用社交登录,必须在使用前配置PianoID共享实例。

PianoID.shared.aid = "<PUBLISHER_AID>"
PianoID.shared.delegate = self

还必须实现您的应用代理的 application(_:open:options:) 方法

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
    return PianoOAuth.PianoIDApplicationDelegate.shared.application(app, open: url, options: options)
}

对于iOS 8及较低版本,您必须实现应用代理已弃用的 application(_:open:sourceApplication:annotation:) 方法

func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
    return PianoOAuth.PianoIDApplicationDelegate.shared.application(application, open: url, sourceApplication: sourceApplication, annotation: annotation)
}

登录

PianoID.shared.signIn()

注销

PianoID.shared.signOut(token: "<TOKEN>")

其他设置

PianoID.shared.isSandbox = true // for using sandbox application
PianoID.shared.widgetType = .login // or .register for choosing default screen 
PianoID.shared.signUpEnabled = false // for enabling/disabling signUp
本地Google登录SDK

您必须实现应用代理的 application(_:didFinishLaunchingWithOptions:) 方法

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    PianoID.shared.googleClientId = "<PUBLISHER_GOOGLE_CLIENT_ID>"    
    return true
}

<PUBLISHER_GOOGLE_CLIENT_ID> 的信息可以在下面找到:[获取OAuth客户端ID](https://developers.google.com/identity/sign-in/ios/start-integrating#get_an_oauth_client_id)

还应该按照以下说明配置URL方案:[向项目添加URL方案](https://developers.google.com/identity/sign-in/ios/start-integrating#add_a_url_scheme_to_your_project)

本地Facebook登录SDK

您必须实现应用代理的 application(_:didFinishLaunchingWithOptions:) 方法

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {    
    PianoOAuth.PianoIDApplicationDelegate.shared.application(application, didFinishLaunchingWithOptions: launchOptions)
    return true
}

还应该按照以下说明配置您的应用:[配置设置](https://developers.facebook.com/docs/swift/register-your-app#configuresettings)

SDK中的无密码登录

这些设置应按照https://docs.piano.io/enabling-passwordless-checkout/在Piano ID中进行配置。当前配置在移动应用程序中不进行额外设置即可应用

PianoIDDelegate 协议
func signIn(result: PianoIDSignInResult!, withError error: Error!);

func signOut(withError error: Error!);

func cancel();