Skip to content

Instantly share code, notes, and snippets.

@cozzin
Created January 29, 2018 04:34
Show Gist options
  • Save cozzin/fc9cc20cf25be5f24d16adf7d14153d3 to your computer and use it in GitHub Desktop.
Save cozzin/fc9cc20cf25be5f24d16adf7d14153d3 to your computer and use it in GitHub Desktop.
iOS Local Push
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
// push received
}
- (void)setLocalPush {
UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init];
content.title = [NSString localizedUserNotificationStringForKey:@"Wake up!" arguments:nil];
content.body = [NSString localizedUserNotificationStringForKey:@"Rise and shine! It's morning time!"
arguments:nil];
UNTimeIntervalNotificationTrigger* trigger = [UNTimeIntervalNotificationTrigger
triggerWithTimeInterval:5 repeats:NO];
UNNotificationRequest* request = [UNNotificationRequest
requestWithIdentifier:@"MorningAlarm" content:content trigger:trigger];
UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter];
[center addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) {
if (error != nil) {
NSLog(@"%@", error.localizedDescription);
}
}];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment