Created
March 7, 2014 01:12
-
-
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.
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)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]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
NOTE: I have also enabled remote notifications