Integrate your app / iOS SDK integration |
Follow these steps to manually integrate Localytics into your iOS app.
#import "Localytics.h"
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [Localytics integrate:@"App Key"]; if (application.applicationState != UIApplicationStateBackground) { [Localytics openSession]; }
if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) { UIUserNotificationType types = (UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound); UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:types categories:nil]; [application registerUserNotificationSettings:settings]; [application registerForRemoteNotifications]; } else { [application registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)]; } return YES; }
if (launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey]) { [Localytics handlePushNotificationOpened:[launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey]]; }
- (void)applicationDidBecomeActive:(UIApplication *)application { [Localytics openSession]; [Localytics upload]; } - (void)applicationWillEnterForeground:(UIApplication *)application { [Localytics openSession]; [Localytics upload]; }
- (void)applicationWillResignActive:(UIApplication *)application { [Localytics dismissCurrentInAppMessage]; [Localytics closeSession]; [Localytics upload]; } - (void)applicationDidEnterBackground:(UIApplication *)application { [Localytics dismissCurrentInAppMessage]; [Localytics closeSession]; [Localytics upload]; }
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { [Localytics setPushToken:deviceToken]; } - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { NSLog(@"Failed to register for remote notifications: %@", [error description]); } - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { [Localytics handlePushNotificationOpened:userInfo]; completionHandler(UIBackgroundFetchResultNoData); }
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { return [Localytics handleTestModeURL:url]; }