当应用程序处于后台状态时,确定是否点击通知横幅或中心通知以启动应用程序
Determine if notification banner or notification in center was tapped to launch the app when app is background state
我检查了很多线程和 Apple Documentation 以确定应用程序是否在点击通知时启动。
我只想在用户点击通知时处理推送通知。
我无法弄清楚 application:didReceiveRemoteNotification:fetchCompletionHandler:
被调用的原因。
当应用程序处于后台时,如何检查此方法是在点击通知时调用还是直接从推送中调用。
谢谢。
- (void)application:(UIApplication *)app didReceiveRemoteNotification:(NSDictionary *)userInfo {
//No Need to store the push notification if it is in active or in closed state we can directly navigate to the screens
NSLog(@"notification didReceive method called");
if([app applicationState] == UIApplicationStateInactive) {
//If the application state was inactive, this means the user pressed an action button
//Handle the code after push notification received
}
else if ([app applicationState] == UIApplicationStateActive) {
//Application is in Active state handle the push notification here
}
}
这里是推送通知的几个步骤
1).当您的应用程序被杀死时,既不活跃也不在后台。在这种情况下,didFinishLaunchingWithOptions
将在您收到任何通知时致电。
2).当您的应用程序处于活动状态或处于后台时,在这种情况下 didReceiveRemoteNotification:fetchCompletionHandler**
将被调用。您必须在此处确定应用程序状态,如下所示。
if ( application.applicationState == UIApplicationStateActive ) {
// app was already in the foreground
}
else {
// app was just brought from background to foreground
}
我检查了很多线程和 Apple Documentation 以确定应用程序是否在点击通知时启动。
我只想在用户点击通知时处理推送通知。
我无法弄清楚 application:didReceiveRemoteNotification:fetchCompletionHandler:
被调用的原因。
当应用程序处于后台时,如何检查此方法是在点击通知时调用还是直接从推送中调用。
谢谢。
- (void)application:(UIApplication *)app didReceiveRemoteNotification:(NSDictionary *)userInfo {
//No Need to store the push notification if it is in active or in closed state we can directly navigate to the screens
NSLog(@"notification didReceive method called");
if([app applicationState] == UIApplicationStateInactive) {
//If the application state was inactive, this means the user pressed an action button
//Handle the code after push notification received
}
else if ([app applicationState] == UIApplicationStateActive) {
//Application is in Active state handle the push notification here
}
}
这里是推送通知的几个步骤
1).当您的应用程序被杀死时,既不活跃也不在后台。在这种情况下,didFinishLaunchingWithOptions
将在您收到任何通知时致电。
2).当您的应用程序处于活动状态或处于后台时,在这种情况下 didReceiveRemoteNotification:fetchCompletionHandler**
将被调用。您必须在此处确定应用程序状态,如下所示。
if ( application.applicationState == UIApplicationStateActive ) {
// app was already in the foreground
}
else {
// app was just brought from background to foreground
}