【发布时间】:2017-05-31 09:13:21
【问题描述】:
我正在尝试很多,但尚未成功在应用程序被终止状态时获得静默通知
这是我正在尝试的代码..
APS 数据:
{
"aps": {
"content-available": 1,
"sound": ""
}
}
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
NSDictionary *userInfo1 = userInfo;
NSLog(@"userInfo: %@", userInfo1);
//self.textView.text = [userInfo description];
// We can determine whether an application is launched as a result of the user tapping the action
// button or whether the notification was delivered to the already-running application by examining
// the application state.
if (application.applicationState == UIApplicationStateActive)
{
//opened from a push notification when the app was on background
NSLog(@"userInfoUIApplicationStateactive->%@",[userInfo objectForKey:@"aps"]);
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Did receive a Remote Notification" message:[NSString stringWithFormat:@"Your App name received this notification while it was Running:\n%@",[[userInfo objectForKey:@"aps"] objectForKey:@"alert"]]delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
}
else
{
// a push notification when the app is running. So that you can display an alert and push in any view
NSLog(@"userInfoUIApplicationStateBackground->%@",[userInfo objectForKey:@"aps"]);
[self scheduleAlarmForDate1:[NSDate date]alarmDict:userInfo];
}
}
【问题讨论】:
-
查看
application:didReceiveRemoteNotification:fetchCompletionHandler:甚至application:didReceiveRemoteNotification:的文档(讨论部分)建议实施另一个。 -
但是当 {"aps":{"alert":"Enter your message","badge":1,"sound":"default"}} 工作正常,甚至终止状态时
-
@larme 你能详细说明一下吗.....
-
" 另外,如果您启用了远程通知后台模式,系统会启动您的应用程序(或将其从挂起状态唤醒)并在远程通知到达时将其置于后台状态。但是,如果用户强制退出应用,系统不会自动启动您的应用。在这种情况下,用户必须重新启动您的应用或重启设备,然后系统才会再次尝试自动启动您的应用。"
-
我正在尝试很多但尚未成功在应用程序被杀死状态时获得静默通知老兄,很抱歉告诉你这个,但是,当应用程序被杀死时静默通知不起作用,无论你做什么都不会工作。
标签: ios objective-c silent-notification