I am trying to send a receipt back to the website when a push notification
has been delivered to the phone no matter what the state of the app is in (foreground, background, closed). I have attached my code and the iGotIt is just a https
call to the server that doesn't get called. What do I need to do in order to get the app to do something when it receives a push notification
?
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
{
[application registerUserNotificationSettings:
[UIUserNotificationSettings settingsForTypes:
(UIUserNotificationTypeSound |
UIUserNotificationTypeAlert |
UIUserNotificationTypeBadge) categories:nil]];
[application registerForRemoteNotifications];
}
else
{
[application registerForRemoteNotificationTypes:
(UIUserNotificationTypeBadge |
UIUserNotificationTypeSound |
UIUserNotificationTypeAlert)];
}
NSDictionary *userInfo = launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey];
NSString *messagePre = nil;
NSString *message = nil;
id alert = [userInfo objectForKey:@"aps"];
if ([alert isKindOfClass:[NSString class]]) {
messagePre = alert;
} else if ([alert isKindOfClass:[NSDictionary class]]) {
messagePre = [alert objectForKey:@"alert"];
}
NSArray *messageSplit = [messagePre componentsSeparatedByString:@"|"];
serviceID = [messageSplit objectAtIndex:0];
message =[messageSplit objectAtIndex:1];
UIAlertView *alertRC = [[UIAlertView alloc]initWithTitle: @"New Road Call"
message: message
delegate: self
cancelButtonTitle:nil
otherButtonTitles:@"View",nil];
[alertRC show];
//Accept push notification when app is not open
if (userInfo) {
[self iGotIt];
}
return YES;
}
Thanks in advance for any help you can provide