gpt4 book ai didi

ios - 检测从推送通知打开的应用程序(后台获取)

转载 作者:行者123 更新时间:2023-11-29 02:07:01 25 4
gpt4 key购买 nike

我使用 UIBackgroundFetchResult 来捕获推送通知,如下面的代码...我还使用内容可用性 = 1 在后台模式下进行检测

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

推送即将到来并在应用程序处于事件状态或后台模式时始终在此处执行但是当我打开推送时,我无法检测到应用程序是否从推送中打开,因为它总是进入 if 状态

 if ( (application.applicationState == UIApplicationStateInactive || application.applicationState == UIApplicationStateBackground)  && (NotiType == 1 || NotiType == 2))
{

}

最佳答案

您可以通过应用委托(delegate)方法检查您的应用是否从 APNS(Apple 推送通知服务)启动

application:didFinishLaunchingWithOptions:

您可以在其中检查应用是否通过通知启动,

-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

if (launchOptions != nil) {
// Launched from push notification
NSDictionary *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];

}
}

如果您的应用程序在后台运行,则不会调用此方法。为此,您可以通过这种方式 checkin 另一种方法,

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
if ( application.applicationState == UIApplicationStateInactive || application.applicationState == UIApplicationStateBackground )
{
//opened from a push notification when the app was on background
}
}

HTH,享受编码吧!

关于ios - 检测从推送通知打开的应用程序(后台获取),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29679808/

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