我能够向我的 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
}
但无法在上面的代码的帮助下显示我的消息。上面的代码仅在我的应用程序打开且处于前台状态时才有效,而不是仅显示此警报,否则不显示。
请帮忙。
Thanks.
当应用程序完全终止时获取通知代码
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)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
}
}
}
欲了解更多信息,请访问此链接:应用程序终止时处理推送通知
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)