Apptilaus Subscription Analytics and Reporting,iOS的SDK
概述
Apptilaus iOS SDK是一个开源SDK,它通过Apptilaus服务提供了一种分析跨设备订阅的最简单方法。
目录
示例
在 示例目录
中有适用于 iOS (Objective-C)
和 iOS (Swift)
的示例应用。您可以通过打开任意这些 Xcode 项目,查看 Apptilaus SDK 集成的示例。
使用库
以下是使用 Xcode 将 Apptilaus SDK 集成到您的 iOS 项目的步骤。
将SDK添加到您的项目中
如果您使用的是 CocoaPods,可以将以下行添加到您的 Podfile
中:
pod 'Apptilaus', '~> 1.0.5'
或者
pod 'Apptilaus', :git => 'https://github.com/Apptilaus/ios_subscriptions_sdk.git', :tag => '1.0.5'
在项目目录中运行 $ pod install
。
如果您使用的是 Carthage,可以将以下行添加到您的 Cartfile
中,并从 此处 进行下一步操作:
github "Apptilaus/ios_subscriptions_sdk"
添加iOS框架
- 在项目导航器中选择您的项目
- 在主视图的左侧,选择您的目标
- 在《构建阶段》选项卡中,展开《链接二进制与库》组
- 在该部分底部,选择
+
按钮 - 选择
AdSupport.framework
,然后点击添加
按钮 - 重复上述步骤以添加
iAd.framework
和StoreKit.framework
- 将框架的状态更改为
可选
。
前置条件
在开始之前,您必须执行上述步骤。
基本设置
- 将以下导入定义添加到您的应用程序代理中
Swift
import Apptilaus
Objective-C
#import <Apptilaus/Apptilaus-umbrella.h>
- 在您的应用程序代理的
didFinishLaunching
或didFinishLaunchingWithOptions
方法中调用Apptilaus
。
Swift
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Your other application code.....
// We've recommend to implement Apptilaus Library right before the end of the method.
let apptilausAppId = "AppID"
let apptilausToken = "AppToken"
ApptilausManager.shared.setup(withAppId: apptilausAppId, appToken: apptilausToken)
}
Objective-C
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Your other application code.....
// We've recommend to implement Apptilaus Library right before the end of the method.
NSString *apptilausAppId = @"AppID";
NSString *apptilausToken = @"AppToken";
[ApptilausManager.shared setupWithAppId:apptilausAppId appToken:apptilausToken enableSessionTracking:NO];
}
注意:以这种方式初始化Apptilaus SDK 非常重要
。否则,它将无法正常工作。
将AppID
和AppToken
替换为您相应的App ID和App Token。您可以在管理面板中找到应用凭证。
注册订阅
在您的SKPaymentTransactionObserver
中添加以下调用以在SKPaymentQueue
中注册购买
Swift
func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
for transaction in transactions {
// Your purchase processing code
if transaction.transactionState == .purchased {
ApptilausManager.shared.register(transaction: transaction)
}
}
}
Objective-C
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray<SKPaymentTransaction *> *)transactions {
for (SKPaymentTransaction *transaction in transactions) {
if (transaction.transactionState == SKPaymentTransactionStatePurchased) {
[[ApptilausManager shared] registerWithTransaction:transaction customParams:nil];
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
} else if (transaction.transactionState == SKPaymentTransactionStateFailed) {
NSLog(@"Transaction %@ failed with error: %@", transaction, transaction.error);
}
}
}
使用参数注册订阅
您还可以在购买注册方法中添加自定义参数,添加以下行
Swift
func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
for transaction in transactions {
//Your purchase processing code
if transaction.transactionState == .purchased {
let customParameters: [String : Any] = [
"foo": "bar",
"goats_count": 123
];
ApptilausManager.shared.register(transaction: transaction, customParams: customParameters)
}
}
Objective-C
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray<SKPaymentTransaction *> *)transactions {
for (SKPaymentTransaction *transaction in transactions) {
if (transaction.transactionState == SKPaymentTransactionStatePurchased) {
NSDictionary<NSString *, id> *customParams = @{
@"foo": @"bar",
@"goats_count": @123
};
[[ApptilausManager shared] registerWithTransaction:transaction customParams:customParams];
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
} else if (transaction.transactionState == SKPaymentTransactionStateFailed) {
NSLog(@"Transaction %@ failed with error: %@", transaction, transaction.error);
}
}
}
高级设置
会话跟踪
为了跟踪第一次会话和用户活动,在调用设置方法时使用 sessionTrackingEnabled
参数
Swift
ApptilausManager.shared.setup(withAppId: apptilausAppId, appToken: apptilausToken, enableSessionTracking: true)
Objective-C
[ApptilausManager.shared setupWithAppId:apptilausAppId appToken:apptilausToken enableSessionTracking:YES];
GDPR 删除权
根据欧盟通用数据保护条例(GDPR)第17条,您可以在用户行使被遗忘权时通知 Apptilaus。调用以下方法将指示 Apptilaus SDK 将用户的遗忘选择传达给 Apptilaus 后端和数据存储
Swift
ApptilausManager.shared.gdprOptOut(customParams: nil) { (success, errorOpt) in
if (success) {
print("Opt-out success")
} else {
print("Opt-out error: \(errorOpt)")
}
Objective-C
[ApptilausManager.shared gdprOptOutWithCustomParams:nil completionHandler:^(BOOL success, NSError *error) {
if (success) {
NSLog(@"Opt-out success");
} else {
NSLog(@"Opt-out error: %@", error);
}
}];
收到此信息后,Apptilaus 将删除用户数据,Apptilaus SDK 将停止跟踪用户。今后,Apptilaus 不会存储此设备发出的任何请求。
本地设置
要与您自己的 Apptilaus 服务安装交互,您也可以在应用程序代理的 didFinishLaunching
或 didFinishLaunchingWithOptions
方法中设置自定义基本 URL
Swift
ApptilausManager.shared.sessionUrl = "https://subscriptions.custom.domain/"
Objective-C
ApptilausManager.shared.sessionUrl = @"https://subscriptions.custom.domain/";
用户丰富信息
您可以可选地设置您的内部用户 ID 字符串以跟踪用户购买行为。这是可以在任何时刻完成的,例如在应用程序启动期间,或在应用程序认证过程之后。
Swift
ApptilausManager.shared.userId = "123456789"
Objective-C
ApptilausManager.shared.userId = @"123456789";
构建您的应用
构建并运行您的应用。如果构建成功,您应该仔细阅读控制台中的 SDK 日志。在完成购买后,您应该看到信息日志 [Apptilaus]: 购买过程已处理
。
许可证和版权
Apptilaus SDK 采用 MIT 许可证授权。
Apptilaus 版本 (c) 2018-2019 版权所有
在此特此免费授予任何人获得此软件及其相关文档文件(以下简称“软件”)的副本的权利,以不受限制地处理该软件,包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或销售软件副本,并允许向提供软件的个人提供如此操作的权利,但以以下条件为限:
应在所有副本或实质部分中包含上述版权声明和本许可声明。
软件按“现状”提供,不提供任何明示或暗示保证,包括但不限于适销性、特定目的适用性和非侵权性保证。在任何情况下,作者或版权所有者对任何索赔、损害或其他责任,无论是基于合同、侵权或任何其他原因,均不承担责任,无论该索赔、损害或其他责任是否源于、源于或与软件或软件的使用或其他交易有关。