Omnisense iOS SDK

Connect your app to Omnisense

Drag and drop the Omnisense.framework in your project

Open up the AppDelegate.m file and import the library

#import <Omnisense/Omnisense.h>

Then activate the app by setting its Omnisense api key in application:didFinishLaunchingWithOptions:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//This line initializes Omnisense and performs all necessary setup.
[Omnisense setAppIdentifier:@"YOUR_APP_IDENTIFIER" apiKey:@"YOUR_APP_API_KEY"];

return YES;
}

User data recording

User profile management

To identify the user on Omnisense (after login or sign up), create an OSUser and set it as the current user.

OSUser * user = [[OSUser alloc] init];
user.email = @"john.doe@gmail.com";
user.facebookId = @"12143534535646";
user.firstName = @"John";
user.lastName = "Doe";

[Omnisense setCurrentUser:user];

To identify a user on Omnisense, an email OR the Facebook ID must at least be set. If not, other attributes won't be sync with Omnisense. See the OSUser.h file for all available attributes

If you want to add or update some of the user attributes, you can get the current user with the method getCurrentUser and change the values. You will have to call the saveCurrentUser after settings the values in order to save them to Omnisense.

After a "log out", simply call the resetCurrentUser to remove the current user.

User custom events recording

To record an event made by the user in the app, call the record event method with segmentation.

[Omnisense recordEvent:@"product_view" segmentation:@{@"product_name": @"The best roduct ever",@"category": @"New stuff"}];

The segmentation is a dictionary of event parameters that only contains string values.

Remote notifications

Register to push notifications

To register the current device for push, call UIApplication's registerForRemoteNotifications method from the app delegate's application:didFinishLaunchingWithOptions:

If the registration is successful, the callback method application:didRegisterForRemoteNotificationsWithDeviceToken: in the application delegate will be executed. You will need to implement this method and use it to inform Omnisense about this new device.

- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)token {

    [Omnisense registerAppForRemoteNotificationsWithDeviceToken:token];

}

Handle incoming push notifications

When a push notification is openned on iOS while the associated application is running in the background, the callback method application:didReceiveRemoteNotification: in the application delegate will be executed. You will need to implement this method and use it to inform Omnisense about the openning of the push notification.

- (void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {

    [Omnisense handleRemoteNotification:userInfo];

}

When a push notification is received on iOS while the associated application is not in the foreground, it is displayed in the iOS Notification Center and/or a banner will appear at the top of the screen. However, if the notification is received while the associated app is in the foreground, it is up to the application to handle the display of said notification if desired. Depending on your use case, you may want to show an alert to the user, or fetch new data from the server in order to refresh the UI.

Whatever the case, you will need to implement the application:didReceiveRemoteNotification: method in the app delegate in order to handle incoming remote notifications while the app is in the foreground.

Conversion data

In case you want to use Omnisense conversion data at first launch in your app, you can use the following method before setting the Api Key.

+ (void) conversionDataHandler:(void (^)(NSDictionary* conversionData, NSError *error))block;

Conversion data are disk cached, you can get it anywhere in the app using this method.

+ (NSDictionary*) conversionData;

Facebook app installs

To track Facebook app install, set a specific Omnisense link into the deferred app link parameter of your Facebook campaign. Use method + (NSURL*) handleFacebookDeferredAppLink:(NSURL*)url to handle the Facebook deferred app link with Omnisense. It return the app link url if it's not an Omnisense link.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  if (launchOptions[UIApplicationLaunchOptionsURLKey] == nil) {
    [FBSDKAppLinkUtility fetchDeferredAppLink:^(NSURL *url, NSError *error) {
      if (error) {
        NSLog(@"Received error while fetching deferred app link %@", error);
      }
      if ([Omnisense handleFacebookDeferredAppLink:url]) {
        [[UIApplication sharedApplication] openURL:url];
      }
    }];
  }
  return YES;
}

In case of Facebook app install, the block method conversionDataHandler: does not return any conversion data but you can still get them from the disk cache data with + (NSDictionary*) conversionData;.

License

Copyright (c) 2016 I See U. All rights reserved.