Last active
December 2, 2017 19:52
-
-
Save bouchtaoui-dev/a0ba940fb72fc1af74d1f1b1673d9f98 to your computer and use it in GitHub Desktop.
This file contains hidden or 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) notifyMessage: (NSString*) sender withMessage: (NSString*) message { | |
| // source: http://useyourloaf.com/blog/local-notifications-with-ios-10/ | |
| NSLog(@"BackgroundServerice: Send a notification!"); | |
| message = message?message:@""; | |
| UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; | |
| // Create a content | |
| UNMutableNotificationContent *content = [UNMutableNotificationContent new]; | |
| content.title = sender; | |
| content.body = [ NSString stringWithCString:[ message cStringUsingEncoding:NSUTF8StringEncoding ] | |
| encoding:NSNonLossyASCIIStringEncoding ]; | |
| content.sound = [ UNNotificationSound defaultSound ]; | |
| //content.badge = 1; // <-- shows badge number on app icon. | |
| // Schedule trigger time after 0 sec. | |
| UNTimeIntervalNotificationTrigger *trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:0.1 | |
| repeats:NO]; | |
| NSString *identifier = @"MYLocalNotification"; | |
| UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:identifier | |
| content:content | |
| trigger:trigger]; | |
| [center addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) { | |
| if (error != nil) { | |
| NSLog(@"BackgroundServerice: Something went wrong with sending LOCAL Notification: %@",error); | |
| } | |
| }]; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment