我使用此代码将推送通知中的应用程序从接近后台唤醒为
UIMutableUserNotificationAction *action2;
action2 = [[UIMutableUserNotificationAction alloc] init];
[action2 setActivationMode:UIUserNotificationActivationModeBackground];////UIUserNotificationActivationModeBackground
[action2 setTitle:@"ACCEPT"];
[action2 setIdentifier:NotificationActionTwoIdent];
[action2 setDestructive:NO];
[action2 setAuthenticationRequired:NO];
现在我按照以下方法点击网络服务 //远程通知
- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo completionHandler:(void (^)())completionHandler
{
/Call to web services.
//show local notification in background
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
if (localNotification == nil)
{
return;
}
else
{
localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:60];
localNotification.alertAction = nil;
localNotification.soundName = UILocalNotificationDefaultSoundName;
localNotification.alertBody = [NSString stringWithFormat:@"Worked=> %@",jsonArray];
localNotification.alertAction = NSLocalizedString(@"Read Msg", nil);
localNotification.applicationIconBadgeNumber=1;
localNotification.repeatInterval=0;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
}
}
我在应用中启用了后台提取功能。我的问题是
答案 0 :(得分:1)
我的实施方式如下:
- (void)application:(UIApplication *)application handleEventsForBackgroundURLSession:(NSString *)identifier
completionHandler:(void (^)())completionHandler {
self.backgroundSessionCompletionHandler = completionHandler;
//add notification
[self presentNotification];
}
-(void)presentNotification{
UILocalNotification* localNotification = [[UILocalNotification alloc] init];
localNotification.alertBody = @"Upload Complete!";
localNotification.alertAction = @"Background Transfer Upload!";
//On sound
localNotification.soundName = UILocalNotificationDefaultSoundName;
//increase the badge number of application plus 1
localNotification.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber] + 1;
[[UIApplication sharedApplication] presentLocalNotificationNow:localNotification];
}
答案 1 :(得分:0)
在调用Web服务之后,您应该调用完成处理程序:
- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forLocalNotification:(UILocalNotification *)notification completionHandler:(void(^)())completionHandler
{
//Call to web services.
if(completionHandler != nil)
completionHandler();
}