omniata-ios-sdk 2.2.3

omniata-ios-sdk 2.2.3

测试已测试
Lang语言 Obj-CObjective C
许可协议 BSD
发布最后发布2016年6月

刘军 维护。



  • Omniata

有关 Omniata 集成文档,请参阅 此处

功能和技术描述

Omniata iOS SDK 使用 Objective-C 实现。默认情况下,SDK 不记录任何内容,即使用 SMT_LOG_NONE 日志级别。可以使用 iOmniataAPI 的 setLogLevel 方法来调整日志级别。在开发和测试时,可能需要更详细的日志级别。

请注意,SDK 使用 NSMutableURLRequest 类进行 Channel API 和 Event API 的通信。这个类相当有限,不允许设置连接超时或请求超时。

发行说明

此版本与上一版本 v2.0.0 兼容。变更细节:将调试级别统一到 Android(适用于 Unity 使用)。

Event API

iOS SDK 自动在 om_load 事件中添加 Event 参数

  • om_device:设备型号,通过代码块得到
size_t size;
  sysctlbyname("hw.machine", NULL, &size, NULL, 0);
  char *machine = malloc(size);
  sysctlbyname("hw.machine", machine, &size, NULL, 0);
  NSString *platform = [NSString stringWithUTF8String:machine];
  free(machine);
  return platform;
  • om_platform:平台:ios
  • om_os_version:操作系统的版本,[[UIDevice currentDevice] systemVersion]
  • om_sdk_version:SDK 的版本
  • om_discarded:SDK 已丢弃的累积事件数,因为交付失败。

整合 Omniata iOS SDK

入门

在使用 iOmnitaAPI 时包含此头文件

#import <iOmniataAPI/iOmniataAPI.h>

初始化

初始化方法可以安全地从多个线程同时调用多次,但是只有第一次调用会初始化。随后的调用将被忽略。是您用于访问 Omniata Panel 的 URL 中的组织部分,即 https://organization.panel.omniata.com 的箭头 -> 组织。

NSString * api_key = @"<API_KEY>";
NSString * user_id = @"<USER_ID>";
NSString * org = @"<ORG_NAME>";
[iOmniataAPI initializeWithApiKey:api_key api_key: UserId:user_id OrgName:org]; // Tracks against production API 

设置 API 密钥和 UID

iOS SDK 现在只支持一次初始化。但是可以使用以下方法重置 API 密钥和 uid。随后跟踪的事件将使用更新的 api_key 和 user_id 替换。

[iOmniataAPI setApiKey:api_key];
[iOmniataAPI setUserId:user_id];

跟踪加载事件

[iOmniataAPI trackLoadEvent];

跟踪收入事件

[iOmniataAPI trackPurchaseEvent:99.9 currency_code: @"EUR"];

跟踪自定义事件

NSDictionary *dictionary = [[NSDictionary alloc] initWithObjectsAndKeys:
                                @"21", @"cash_balance",
                                @"7", @"level",
                                nil];

[iOmniataAPI trackEvent: @”quest_complete”: dictionary];

跟踪广告商ID

[iOmniataAPI trackAdvertiserID];

加载渠道消息

通过调用 loadMessages 进行渠道API请求。在内部,SDK使用HTTP调用Channel API。调用通过 [NSURLConnection sendAsynchronousRequest] 异步进行。loadMessages作为参数提供的 completionBlock 在Channel API调用完成后调用。在成功的情况下,可以使用 getChannelMessages 获取消息。目前,一次最多只能有一个Channel API调用在进行中。

[iOmniataAPI loadMessagesForChannel:40 completionHandler:^(OMT_CHANNEL_STATUS cs){
 NSArray* message = [iOmniataAPI getChannelMessages];
}];

调试

[iOmniataAPI setLogLevel:SMT_LOG_VERBOSE];

推送通知

  • 在应用程序代理中,添加对 registerForRemoteNotificationTypes 的调用。根据iOS 8发行说明,“使用本地或推送通知的应用必须通过使用 UIUserNotificationSettings 对象,明确注册它们向用户显示的警报类型”,需要对iOS 8进行一些更改。
- (void)applicationDidFinishLaunching:(UIApplication *)app {
  // other setup tasks here....

  // Initialize OmniataSDK
  [iOmniataAPI initializeWithApiKey:@"<API_KEY>" UserId:@"<USER_ID>" AndDebug:YES]; // Tracks to test API
  // Register for notifications here
    // For iOS 8 and later, do the UIUserNotificationSettings setting
    #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000
    if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)]) {
        UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];
        [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
        [[UIApplication sharedApplication] registerForRemoteNotifications];
    } else {
        [[UIApplication sharedApplication] registerForRemoteNotificationTypes: UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge];
    }
    // For iOS version less than iOS 8
    #else
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes: UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge];
    #endif
    return YES;
 }
  • 通过SDK向Omniata获取推送令牌。在iOS库中有一个可以用于获取推送令牌的方法。didRegisterForRemoteNotificationsWithDeviceToken 查看更多 信息
[iOmniataAPI initializeWithApiKey:@"<API_KEY>" UserId:@"<USER_ID>" OrgName:<ORG>];
...
[iOmniataAPI enablePushNotifications:deviceToken];

通过Omniata SDK禁用,调用此方法将告诉Omniata,用户不再有资格接收推送通知。

[iOmniataAPI disablePushNotifications];
  • 更新CocoaPods发布版本,例如发布2.2.2版本的SDK,修改 omniata-ios-sdk.podspec 文件中的版本号,首先验证pod库
pod lib lint

推送到pod trunk

git commit -m "Release 2.2.2"
git tag '2.2.2'
git push --tags
pod trunk register
pod trunk push omniata-ios-sdk.podspec

许可证

第三方软件许可证。SBJson用于JSON处理,请检查仓库中LICENSE文件的详细信息。