PianoOAuth 2.8.3

PianoOAuth 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 执行
composer.execute()
PianoComposerDelegate 协议
// 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;

Piano账户用户提供者

用法
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()
PianoOAuthDelegate 协议
func loginSucceeded(accessToken: String)
func loginCancelled() 
屏幕截图

iPhone example

iPad example

钢琴 ID 用户提供者

钢琴 ID

钢琴ID需要向您项目添加一个自定义URL方案。要添加:打开您的项目配置,从目标部分选择您的应用,然后选择“信息”标签,展开“URL类型”部分。

将 `io.piano.id.<PUBLISHER_AID_LOWERCASE>` 设置为URL方案。例如:[点击查看](./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
原生谷歌登录SDK

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

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

有关 `` 的信息,请参阅此处:https://developers.google.com/identity/sign-in/ios/start-integrating#get_an_oauth_client_id

还应按以下说明配置URL方案:https://developers.google.com/identity/sign-in/ios/start-integrating#add_a_url_scheme_to_your_project

原生脸图书签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中的无密码登录

这些设置应在Piano ID中根据https://docs.piano.io/enabling-passwordless-checkout/进行配置。当前配置已在移动应用程序中应用,无需额外设置

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

func signOut(withError error: Error!);

func cancel();