我用这个代码从接近背景清醒应用在推送通知的iOS中的通知操作后台获取?
UIMutableUserNotificationAction *action2;
action2 = [[UIMutableUserNotificationAction alloc] init];
[action2 setActivationMode:UIUserNotificationActivationModeBackground];////UIUserNotificationActivationModeBackground
[action2 setTitle:@"ACCEPT"];
[action2 setIdentifier:NotificationActionTwoIdent];
[action2 setDestructive:NO];
[action2 setAuthenticationRequired:NO];
现在我打的Web服务在下面的方法 //远程Notificaiton
- (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];
}
}
我启用后台中取应用程序。我的问题是
- 我正在使用NSURLConnetion类进行网络调用。它在某个时候有效,但似乎没有其他时间。
- 通知警报不会在后台显示。
- 我是否需要使用performFetchWithCompletionHandler completionHandler委托? 任何人都可以帮助我解决这个问题?提前致谢。
你想显示通知,当后台任务完成? –
请检查我的答案,我用这个。 –