InPlayer 的 iOS SDK
InPlayer 的 iOS API 客户端封装器
需求
- iOS 10.0+
- Xcode 10.1+
- Swift 4.2+
安装
CocoaPods
CocoaPods 是 Cocoa 项目的依赖管理器。您可以使用以下命令安装它
$ gem install cocoapods
要使用 CocoaPods 将 InPlayerSDK 集成到您的 Xcode 项目中,请在您的 Podfile
中指定它
source 'https://github.com/CocoaPods/Specs.git'
install! 'cocoapods',
: preserve_pod_file_structure => true
platform :ios, '10.0'
target '<Your Target name>' do
use_frameworks!
pod 'InPlayerSDK'
end
然后,运行以下命令
$ pod install
注意:InPlayerSDK 使用子模块构建。所以如果您愿意,您可以在 Podfile 中这样添加它
pod 'InPlayerSDK' (all features, default)
pod 'InPlayerSDK/Core' (includes Core features - Account, Asset, Subscription)
pod 'InPlayerSDK/Payment' (includes Core and Payment modules)
pod 'InPlayerSDK/Notification' (includes Core and Notification modules)
依赖项
本SDK依赖于某些组件,以下是这个列表:
pod 'Alamofire', '5.2.0'
pod 'AWSIoT', '2.13.4' (only Notifications module)
用法
将 InPlayerSDK
导入到您的文件中。
配置
要初始化SDK并开始使用,您必须首先执行以下步骤:
创建配置对象
let configuration = InPlayer.Configuration(clientId: "<YOUR CLIENT ID HERE>", referrer: "<REFERRER URL GOES HERE>" environment: <ENVIORMENT TYPE>)
初始化InPlayer
InPlayer.initialize(configuration: configuration)
服务
InPlayerSDK由五个服务组成:Account
、Asset
、Payment
、Subscription
和 Notification
。
账户
账户相关方法。
示例
认证方法
InPlayer.Account.authenticate(username: "<YOUR USERNAME>", password: "<YOUR PASSWORD>", success: { (authorization) in
// Successfully logged in.
}, failure: { (error) in
// Some error occured.
})
资源
资源相关方法
例子
获取资产详情
InPlayer.Asset.getAsset(id: <ITEM_ID>, success: { (item) in
// Successfully obtained item details.
}, failure: { error in
// Some error occured.
}
检查资产访问权限
InPlayer.Asset.checkAccessForAsset(id: <ITEM_ID>), success: { (itemAccess) in
// You have access to this asset
}, failure: { (error) in
// Some error occured.
})
此外,当检查资产访问权限时,在 itemAccess.item
中存在content
,它可以是一个纯字符串或JSON字符串。为了相应地解析模型并访问其属性(每种类型都有不同的属性),我们鼓励您在使用 success
块时的这种方式
if let ContentType.accedo(asset) = itemAccess.item.parseContent() {
// Parsed content is of type `accedo`, and the `asset` is the resource you can use it
}
支付
支付相关方法
例子
验证购买
InPlayer.Payment.validate(receiptString: <RECEIPT_STRING>, productIdentifier: <PRODUCT_IDENTIFIER>, success: {
// Successfully validated receipt
}, failure: { (error) in
// Some error occured
})
订阅
订阅相关方法
例子
获取账户订阅
InPlayer.Subscription.getSubscriptions(page: 1, limit: 10, success: { (list) in
// Successfully obtained subscription list
}, failure: { (error) in
// Some error occured
})
通知
通知服务有三个方法
public static func subscribe(onStatusChanged: @escaping ( _status: InPlayerNotificationStatus) -> Void,
onMessageReceived: @escaping (_ notification: InPlayerNotification) -> Void,
onError: @escaping (_ error: InPlayerError) -> Void)
和
public static func unsubscribe()
public static func isSubscribed() -> Bool
例子
订阅方法
InPlayer.Notification.subscribe(onStatusChanged: { (status) in
// Notification status changed
}, onMessageReceived: { (message) in
// Because message has type which is enum containing associated value, this is one of the ways to use it.
if case let NotificationType.accessGranted(resource) = message.type {
// Access was granted, you can use resource
}
}, failure: { (error) in
// InPlayerError containing info about what happened
})
贡献
我们感谢社区做出的任何贡献。通过贡献,你同意遵守贡献指南中的行为准则。
许可证
基于MIT许可证,版权所有©2018-present InPlayer。
更多信息请查看LICENSE。