Skip to content

Instantly share code, notes, and snippets.

@bouchtaoui-dev
Last active December 2, 2017 19:52
Show Gist options
  • Select an option

  • Save bouchtaoui-dev/a0ba940fb72fc1af74d1f1b1673d9f98 to your computer and use it in GitHub Desktop.

Select an option

Save bouchtaoui-dev/a0ba940fb72fc1af74d1f1b1673d9f98 to your computer and use it in GitHub Desktop.
- (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