CocoaPods trunk is moving to be read-only. Read more on the blog, there are 18 months to go.

omniata-ios-sdk 2.2.3

omniata-ios-sdk 2.2.3

TestsTested
LangLanguage Obj-CObjective C
License BSD
ReleasedLast Release Jun 2016

Maintained by Jun Liu.



  • By
  • Omniata

Check here for Omniata integration documentation.

Features and technical description

Omniata iOS SDK is implemented using Objective-C. By default SDK does not log anything, i.e. uses SMT_LOG_NONE log level. The method setLogLevel of iOmniataAPI can be used to adjust the log level. When developing and testing a more verbose log level might be useful.

Note the SDK uses NSMutableURLRequest class for the Channel API & Event API communication. The class is rather limited, it doesn't allow setting connection timeout or request timeout.

Release Notes

This version is compatible with the previous version v2.0.0. Changed details: Change the debug level to be unified with Android (for Unity usage).

Event API

The iOS SDK automatic adds Event Parameters in om_load events:

  • om_device: the device model, obtained by code block:
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: the platform: ios
  • om_os_version: the version of the operating system, [[UIDevice currentDevice] systemVersion]
  • om_sdk_version: the version of the SDK
  • om_discarded: the cumulative count of events the SDK has discarded, because the delivery has failed.

Integrating Omniata iOS SDK

Getting Started

Include this header when using iOmnitaAPI

#import <iOmniataAPI/iOmniataAPI.h>

Initialize

Initialization methods can be safely called multiple times or from multiple threads simultaneously, however only the first call initializes. The subsequent calls are ignored. is the organization part of the URL you use to access Omniata Panel, i.e. https://organization.panel.omniata.com -> would be organization.

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 

Set API Key And UID

iOS SDK now only supports one time initialization. But the api key and uid can be reset by using the following method. And the after tracking events will use the updated api_key and user_id instead.

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

Tracking Load Event

[iOmniataAPI trackLoadEvent];

Tracking Revenue Event

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

Tracking Custom Event

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

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

Tracking Advertiser ID

[iOmniataAPI trackAdvertiserID];

Loading Channel Message

A Channel API request is made by calling loadMessages. Internally the SDK calls the Channel API using HTTP. The call is asynchronously make using [NSURLConnection sendAsynchronousRequest]. The completionBlock that is given as a parameter to loadMessages is called after the Channel API call finished. In the successful case the messages can be retrieved using getChannelMessages. Currently, maximum one Channel API call can be in progress at time.

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

Debug

[iOmniataAPI setLogLevel:SMT_LOG_VERBOSE];

Push Notification

  • In the application delegate, add a call to registerForRemoteNotificationTypes. According to iOS 8 release notes, "Apps that use local or push notifications must explicitly register the types of alerts that they display to users by using a UIUserNotificationSettings object", some changes need to be done for 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;
 }
  • Push Token to Omniata with SDK To get the PushToken, there is a method in iOS Library which can be used. didRegisterForRemoteNotificationsWithDeviceToken Check more here
[iOmniataAPI initializeWithApiKey:@"<API_KEY>" UserId:@"<USER_ID>" OrgName:<ORG>];
...
[iOmniataAPI enablePushNotifications:deviceToken];

To disable via Omniata SDK, calling this method will tell Omniata that the user is no longer eligible to receive push notifications.

[iOmniataAPI disablePushNotifications];
  • Update CocoaPods release e.g. release SDK version 2.2.2, modify version number in omniata-ios-sdk.podspec file validate the pod lib first
pod lib lint

push to 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

Licenses

3rd party software licenses. SBJson is used for JSON processing, check detail of the LICENSE file in the repository