gpt4 book ai didi

ios - didReceiveRemoteNotification : fetchCompletionHandler: open from icon vs push notification

转载 作者:IT王子 更新时间:2023-10-29 07:36:52 26 4
gpt4 key购买 nike

我正在尝试实现后台推送通知处理,但我无法确定用户是通过发送的推送通知打开应用程序,还是通过图标打开应用程序。

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {

//************************************************************
// I only want this called if the user opened from swiping the push notification.
// Otherwise I just want to update the local model
//************************************************************
if(applicationState != UIApplicationStateActive) {
MPOOpenViewController *openVc = [[MPOOpenViewController alloc] init];
[self.navigationController pushViewController:openVc animated:NO];
} else {
///Update local model
}

completionHandler(UIBackgroundFetchResultNewData);
}

使用此代码,无论用户如何打开应用程序,应用程序都会向 MPOOpenViewController 打开。我怎样才能做到只有当他们通过滑动通知打开应用程序时才会推送 View Controller ?

使用相同的代码,这在 iOS 6 上有效,但使用新的 iOS 7 方法,它的行为并不像我想要的那样。

编辑:我正在尝试在 iOS 7 上运行该应用程序,我们不支持 iOS 7 之前的任何版本。我在 iOS 6 版本的方法(没有完成处理程序)并且它的行为符合我的预期。你会滑动通知,这会被调用。如果您从图标打开,则永远不会调用该方法。

最佳答案

好吧,我明白了。该方法实际上被调用了两次(一次是在它收到推送时,一次是在用户与图标或通知交互时)。

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {

if(application.applicationState == UIApplicationStateInactive) {

NSLog(@"Inactive");

//Show the view with the content of the push

completionHandler(UIBackgroundFetchResultNewData);

} else if (application.applicationState == UIApplicationStateBackground) {

NSLog(@"Background");

//Refresh the local model

completionHandler(UIBackgroundFetchResultNewData);

} else {

NSLog(@"Active");

//Show an in-app banner

completionHandler(UIBackgroundFetchResultNewData);

}
}

感谢 Tim Castelijns 添加以下内容:

Note: the reason it's called twice is due to the Payload having content_available : 1. If you remove the key and its value, then it will only run upon tapping. This will not solve everyone's problem since some people need that key to be true

关于ios - didReceiveRemoteNotification : fetchCompletionHandler: open from icon vs push notification,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22085234/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com