Instantly share code, notes, and snippets.

Embed
What would you like to do?
Push - Manual - Registration & Setup - Obj-C
- (BOOL)application:(UIApplication \*)application didFinishLaunchingWithOptions:(NSDictionary \*)launchOptions {
// step 1 : register remote notification for ios version >= 10 or < 10
if (@available(iOS 10.0, *)) {
NSLog(@"version greater than or equal to 10");
if (@available(iOS 10.0, *)) {
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self;
[center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert) completionHandler:^(BOOL granted, NSError * _Nullable error){
if (!error && granted) {
[application registerForRemoteNotifications];
NSLog(@"Push registetration success!");
} else {
NSLog(@"Push registration Failed. ERROR : %@ - %@", error.localizedFailureReason, error.localizedDescription);
}
}];
}
} else {
NSLog(@"version less than 10");
UIApplication *application = [UIApplication sharedApplication];
if ([application respondsToSelector:@selector(isRegisteredForRemoteNotifications)]) {
[application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert) categories:nil]];
[application registerForRemoteNotifications];
}
}
// step 2 : (Optinoal get a FlurryMessaging Callback)
[FlurryMessaging setMessagingDelegate:self];
// step 3 : start flurry session
FlurrySessionBuilder* builder = [[[FlurrySessionBuilder alloc] withLogLevel:FlurryLogLevelDebug] withIncludeBackgroundSessionsInMetrics:YES];
[Flurry startSession:@”API_KEY” withOptions:launchOptions withSessionBuilder:builder];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment