Login

Integration Tools

iOS Integration Test

iOS Device Event Log

Android Integration Test

Android Device Event Log

Sandbox Event Log

iOS Device Event Log
Upgrading push integration code for iOS9 compatibility

In iOS 9, Apple seems to have changed its process for generating push tokens. When you do the first install of your app and call "registerForRemoteNotifications" inside callback "didFinishLaunchingWithOptions", Apple sometimes doesn't generate a push token. To ensure that this doesn't happen, call "registerForRemoteNotifications" inside the callback "didRegisterUserNotificationSettings" also. Add the following code in the app delegate. The suggested code works well on all iOS devices (6, 7, 8, 9).


- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
    [[UIApplication sharedApplication] registerForRemoteNotifications];  <-- calling registerForRemoteNotifications again!!
}

Upgrading to SDK version 2.0.0 and above
In this upgrade, you want to accomplish the following:

  • 1. Change the name of our SDK from 'KahunaAnalytics' to 'Kahuna'.
  • 2. Introduce a new API 'loginWithCredentials' to replace all other APIs for sending credentials to Kahuna.
● This upgrade guide can only be used if you are upgrading to SDK version 2.0.0 and above. Otherwise, please look at the upgrade steps below.

● If you are not using ARC, then we would recommend adopting ARC before making these changes. Without ARC some of the compiler errors might be shown as warnings or even completely omitted.

  • 1. Start with a clean checkout from your source control. That way you can revert back to the original configuration if need be.

  • 2. If you are NOT using CocoaPods follow the steps 2a and 2b and then jump to step 4.
  • 3. If you are using CocoaPods follow the steps 3a and 3b.
    • 3a. Change pod name from 'KahunaSDK' to 'Kahuna'.

    • 3b. Run 'Pod Install'. This will remove the old KahunaSDK files and replace it with the new Kahuna files.

  • 4. Change all occurrences of the string 'KahunaAnalytics' to 'Kahuna'. This includes the change from #import "KahunaAnalytics.h" to #import "Kahuna.h". A simple find-replace on your entire project will work in most cases.
    Example:
    From
    #import "KahunaAnalytics.h"
    
    NSDictionary *viewStats = [NSDictionary dictionaryWithObjectsAndKeys:@"41123", @"last_video_id",
                                                @"sports", @"last_genre",
                                                nil];
    [KahunaAnalytics setUserAttributes:viewStats];
    [KahunaAnalytics trackEvent:@"Viewed Video"];
    

    To
    #import "Kahuna.h"
    
    NSDictionary *viewStats = [NSDictionary dictionaryWithObjectsAndKeys:@"41123", @"last_video_id",
                                                @"sports", @"last_genre",
                                                nil];
    [Kahuna setUserAttributes:viewStats];
    [Kahuna trackEvent:@"Viewed Video"];
    

  • 5. Change all occurrences of string 'Kahuna sharedAnalytics' to 'Kahuna sharedInstance'.
    Example:
    From
    ((KahunaAnalytics*)[KahunaAnalytics sharedAnalytics]).delegate = self;
    

    To
    // sharedInstance now returns an 'instancetype'. So there is no need to cast sharedInstance to Kahuna*
    [Kahuna sharedInstance].delegate = self;
    

  • 6. Replace 'startWithKey' API with 'launchWithKey' API. If you were sending credentials with 'startWithKey' or 'launchWithKey' APIs then use the new 'loginWithCredentials' API to send the credentials. If your application does not accept any credentials, then you can skip the call to loginWithCredentials API.
    NOTE : Call the 'launchWithKey' API in the application:didFinishLaunchingWithOptions: method as shown below.

    Here is a mapping of the old APIs to new APIs related to startWithKey and sending credentials.
    ● startWithKey -> Use launchWithKey API instead.
    ● startWithKey:andUsername:andEmail -> Use launchWithKey & loginWithCredentials API instead.
    ● startWithKey:andCredentials -> Use launchWithKey & loginWithCredentials API instead.
    ● launchWithKey:andUsername:andEmail -> Use launchWithKey & loginWithCredentials API instead.
    ● launchWithKey:andCredentials -> Use launchWithKey & loginWithCredentials API instead.

    Example:
    From
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        // NOTE : Kahuna API call for setting Deep Integration mode and setting Kahuna Delegate should be
        // called before the following code.
    
        // Initializing the API
        [KahunaAnalytics startWithKey:@"INSERT_APP_KEY" andUsername:@"John" andEmail:@"john@test.com"];
    
        // Add your app initialization code here
        return YES;
    }
    

    To
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        // NOTE : Kahuna API call for setting Deep Integration mode and setting Kahuna Delegate should be
        // called before the following code.
    
        // Initializing the API
        [Kahuna launchWithKey:@"INSERT_APP_KEY"];
    
        // Login the user. You can skip this below section if you app is an anonymous app.
        NSError *error = nil;
        KahunaUserCredentials *uc = [Kahuna createUserCredentials];
        [uc addCredential:KAHUNA_CREDENTIAL_USERNAME withValue:@"John"];
        [uc addCredential:KAHUNA_CREDENTIAL_EMAIL withValue:@"john@test.com"];
        [Kahuna loginWithCredentials:uc error:&error];
        if (error) {
            NSLog(@"Login Error : %@", error.description);
        }
    
        // Add your app initialization code here
        return YES;
    }
    

  • 7. Sending credentials to Kahuna. The API setUserCredentialsWithKey:andValue has been removed in favor of loginWithCredentials:error:. We now allow multiple entries for the same credential. i.e. multiple email address or google plus ids for the same user.
    Example:
    From
    [KahunaAnalytics setUserCredentialsWithKey:KAHUNA_CREDENTIAL_EMAIL andValue:"john@test.com"];
    

    To
    NSError *error = nil;
    KahunaUserCredentials *uc = [Kahuna createUserCredentials];
    [uc addCredential:KAHUNA_CREDENTIAL_EMAIL withValue:@"john@test.com"];
    [Kahuna loginWithCredentials:uc error:&error];
    if (error) {
        NSLog(@"Login Error : %@", error.description);
    }
    

  • 8. Getting credentials from Kahuna. Here is where ARC is required the most. Previously we were returning an NSDictionary*. Now we are returning a KahunaUserCredentials* object. Without ARC, calling 'valueForKey' on a KahunaUserCredentials will throw a run time error, but not show it as an issue during compile time.
    Example:
    From
    NSDictionary *credentials = [KahunaAnalytics getUserCredentials];
    NSString *name = [credentials valueForKey:KAHUNA_CREDENTIAL_USERNAME];
    NSString *email = [credentials KAHUNA_CREDENTIAL_EMAIL];
    

    To
    // Since we allow multiple entries for the same credential we now return an array for each credential as shown below.
    KahunaUserCredentials *kCreds = [Kahuna getUserCredentials];
    NSArray *aryName = [kCreds getCredentialsListForKey:KAHUNA_CREDENTIAL_USERNAME];
    NSArray *aryEmail = [kCreds getCredentialsListForKey:KAHUNA_CREDENTIAL_EMAIL];
    NSString *name = (!aryName.count) ? @"" : aryName[0];
    NSString *email = (!aryEmail.count) ? @"" : aryEmail[0];
    

  • 9. Location Services. The following APIs have been renamed:
    enableLocationMonitoring -> enableLocationServices
    clearLocationMonitoringUserPermissions -> clearLocationServicesUserPermissions
    disableLocationMonitoring -> disableLocationServices

    Example:
    From
    [KahunaAnalytics enableLocationMonitoring:KAHRegionMonitoring withReason:@"User reason"];
    

    To
    [Kahuna enableLocationMonitoring:KAHRegionMonitoringServices withReason:@"User reason"];
    
With the above changes most of your code should be transformed to use the new SDK. If you still have compilation errors check for one of the above steps for guidance.

Upgrading to SDK version 550 and above
This upgrade guide can only be used if you are upgrading to SDK version 550 and above. Otherwise, please look at the upgrade steps below.

  • 1. Change the API 'startWithKey' to 'launchWithKey'. 'startWithKey' and its variants have been deprecated in favor of 'launchWithKey'
  • 2. Move the 'launchWithKey' API into didFinishLaunchingWithOptions as shown below
  • #import "KahunaAnalytics.h"
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        // If you were passing in credentials to the startWithKey API, then use the respective launchWithKey
        // APIs to pass in credentials.
        [KahunaAnalytics launchWithKey:@"INSERT_APP_KEY"];
        // Add your app initialization code here
        return YES;
    }
                

Upgrading your application for iOS 8
This upgrade guide can only be used if you are upgrading your application to iOS 8.
DO NOT UPGRADE unless you are using Xcode 6.

The steps for upgrading to iOS 8 using the Kahuna SDK are outlined below.
In Kahuna SDK versions prior to 459, your didFinishLaunchingWithOptions method looks like this.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Add your app initialization and Kahuna initialization code here
    UIRemoteNotificationType types = UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound;
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:types];
    [KahunaAnalytics handleNotification:[launchOptions valueForKey:
        UIApplicationLaunchOptionsRemoteNotificationKey] withApplicationState:application.applicationState];
    return YES;
}
        

In order to upgrade to iOS 8, you need to replace the contents of didFinishLaunchingWithOptions with the code below:

// Add your app initialization and Kahuna initialization code here
if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerForRemoteNotifications)]) {
    UIUserNotificationType types = UIUserNotificationTypeAlert | UIUserNotificationTypeSound;
    UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:types
                                                                            categories:nil];
    [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
    [[UIApplication sharedApplication] registerForRemoteNotifications];
} else {
    UIRemoteNotificationType types = UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound;
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:types];
}
[KahunaAnalytics handleNotification:[launchOptions valueForKey:
UIApplicationLaunchOptionsRemoteNotificationKey] withApplicationState:application.applicationState];
return YES;

// Call "registerForRemoteNotifications" inside the method "didRegisterUserNotificationSettings" also. This is needed for generating push tokens in iOS9 on fresh installs.
            

The final result will look like this:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Add your app initialization and Kahuna initialization code here
    if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerForRemoteNotifications)]) {
        UIUserNotificationType types = UIUserNotificationTypeAlert | UIUserNotificationTypeSound;
        UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:types
                                                                               categories:nil];
        [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
        [[UIApplication sharedApplication] registerForRemoteNotifications];
    } else {
        UIRemoteNotificationType types = UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound;
        [[UIApplication sharedApplication] registerForRemoteNotificationTypes:types];
    }
    [KahunaAnalytics handleNotification:[launchOptions valueForKey:
    UIApplicationLaunchOptionsRemoteNotificationKey] withApplicationState:application.applicationState];
    return YES;
}

- (void) application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
    [[UIApplication sharedApplication] registerForRemoteNotifications];
}
        

Optional Upgrade (Only if you are not using Deep Integration mode)

Actionable Notifications in iOS 8 - iOS 8 allows notifications to contain actions. The Kahuna SDK supports actionable notifications; in order to implement them, add the following method to your application delegate.

- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)actionIdentifier
                                                      forRemoteNotification:(NSDictionary *)userInfo
                                                          completionHandler:(void (^)())completionHandler
{
    [KahunaAnalytics handleNotification:userInfo withActionIdentifier:actionIdentifier
                                                withApplicationState:application.applicationState];
    // Call the completion handler here
}