Follow these steps to automatically integrate Localytics into your iOS app.
Once data is uploaded, it can't be deleted, so it's a good idea to create a test
app in Localytics and use it to perfect
your instrumentation. Then you can switch the app key to the production app.
-
In your application's delegate file, the file whose default name is
‘<YourApplication>AppDelegate.m’, add the following line under any
existing imports.
-
In the same file, add the following line to the start of
didFinishLaunchingWithOptions. This integrates the Localytics library into the
app, opens the session, and causes an upload on app start.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[Localytics autoIntegrate:@"App Key" launchOptions:launchOptions];
-
Include the following code to register for push notifications.
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;
}
Note: Automatic integration works by becoming the application's delegate. If you
are changing the default delegate, make sure to call the above code
after you do so. Otherwise, Localytics will not
integrate into your application.
-
Test your app. Run your application in the simulator (or on a real device if
possible) and check your Localytics
Dashboard to see the data
being reported. Remember that the upload is only guaranteed when the session is
opened and closed, so any events you tag may not appear until your second
session.
-
Enable background
push for your app.
Congratulations! You're integrated. Check out the data in your
Dashboard or get even more insights
when you start
tagging
events. Don't forget to test your app. Run it in an emulator, or on a real
device if possible.