Created
January 29, 2018 04:34
-
-
Save cozzin/fc9cc20cf25be5f24d16adf7d14153d3 to your computer and use it in GitHub Desktop.
iOS Local Push
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification { | |
// push received | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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
https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/SchedulingandHandlingLocalNotifications.html#//apple_ref/doc/uid/TP40008194-CH5-SW1