Raj*_*Raj 6 iphone push-notification apple-push-notifications ios
我正在做一个推送通知功能是其中一个关键功能的项目.
当我在应用程序中时它工作正常,我收到通知并处理该通知.
但问题是当我在后台并且通知收到我在我的应用程序图标上看到徽章时,当我点击图标我的应用程序正在启动但该didReceiveRemoteNotification方法未被调用,因此我无法处理该通知.
另一个问题是有时它显示通知消息,device notification list有时则没有.
当我通过点击通知列表项目进入我的应用程序时,我didReceiveRemoteNotification可以成功处理通知.我在下面编写代码didFinishLaunchingWithOptions:(NSDictionary *)launchOptions method
NSDictionary* remoteNotif = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (remoteNotif != nil)
{
NSLog(@"didFinishLaunchingWithOptions\nNotification recieved:\n%@",remoteNotif);
notificationData=[[NSDictionary alloc]initWithDictionary:remoteNotif];
[notif saveNotification:remoteNotif];
}
Run Code Online (Sandbox Code Playgroud)
帮我解决这个问题.提前致谢.
您在didfinishlaunch方法中执行的操作也在didReceiveRemoteNotification中执行。当您从后台退出时,不会调用didfinishlaunch 。
- (void)application:(UIApplication*)application didReceiveRemoteNotification:
(NSDictionary*)userInfo
{
UIApplicationState state = [application applicationState];
if (state == UIApplicationStateActive)
{
//What you want to do when your app was active and it got push notification
}
else if (state == UIApplicationStateInactive)
{
//What you want to do when your app was in background and it got push notification
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2918 次 |
| 最近记录: |