Skip to content

Instantly share code, notes, and snippets.

@jasonsilberman
Created March 7, 2014 01:12
Show Gist options
  • Save jasonsilberman/9403142 to your computer and use it in GitHub Desktop.
Save jasonsilberman/9403142 to your computer and use it in GitHub Desktop.
Here is my helper function for sending a UILocalNotification, when it gets called while the app is in the background, it does not fire the notification.
- (void)setLocalNotificationForType:(SPKLocalNotificationType)notificationType fromUser:(NSString *)userName withMessageText:(NSString *)msgText {
NSLog(@"setLocalNotificationForType:fromUser:withMessageText:");
if (! useNotifications) { return; }
NSLog(@"setting notif...");
UILocalNotification *notif = [UILocalNotification new];
notif.userInfo = @{@"handle": _convoHandle, @"room": _convoName};
notif.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber] + 1;
if (notificationType == 1) { // message
notif.alertBody = [NSString stringWithFormat:@"@%@ said: \"%@\"", userName, msgText];
} else if (notificationType == 2) { // image
notif.alertBody = [NSString stringWithFormat:@"@%@ sent an image", userName];
} else {
return;
}
if ([[UIApplication sharedApplication] applicationState] != UIApplicationStateActive) {
[[UIApplication sharedApplication] presentLocalNotificationNow:notif];
}
}
@jasonsilberman
Copy link
Author

NOTE: I have also enabled remote notifications

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment