我可以向我的 IOS 设备发送推送通知。但是,当我单击该通知时,它只会打开应用程序。应用程序内不显示任何消息。
我使用的代码:
if (application.applicationState == UIApplicationStateActive) {
NSString *cancelTitle = @"Close";
NSString *showTitle = @"Show";
NSString *message = [[userInfo valueForKey"aps"] valueForKey"alert"];
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle"Some title"
message:message
delegate:self
cancelButtonTitle:cancelTitle
otherButtonTitles:showTitle, nil];
[alertView show];
[alertView release];
} else {
//Do stuff that you would do if the application was not active
}
但无法在上述代码的帮助下显示我的消息。上面的代码仅在我的应用程序处于前台状态打开时才有效,而不是仅显示此警报。
请帮忙。
谢谢。
当应用程序被完全杀死时获取通知代码
- (BOOL)applicationUIApplication *)application didFinishLaunchingWithOptionsNSDictionary *)launchOptions
{
if (launchOptions != nil)
{
//opened from a push notification when the app is closed
NSDictionary* userInfo = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (userInfo != nil)
{
NSLog(@"userInfo->%@",[userInfo objectForKey"aps"]);
//write you push handle code here
}
}
}
更多信息请点击此链接:Handling Push Notifications when App is Terminated
关于ios - 在应用程序未运行时处理推送通知(即完全被杀死),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38512456/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |