gpt4 book ai didi

ios - 接收解析通知并通过应用程序图标打开应用程序以查看它而不是通知

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

当我收到通知时,我在 AppDelegate.m 中使用此代码

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
[PFPush handlePush:userInfo];
}

因此,如果应用程序已打开并且当前在屏幕上,则会显示通知,或者如果应用程序在后台,点击通知将打开应用程序并显示它。有没有办法点击应用程序图标然后显示通知?例如,用户可能看到通知并想要查看它,然后单击主屏幕上的应用程序图标。有办法实现吗?

最佳答案

点击应用程序图标不会显示与通知相关的任何内容,它只会在正常使用时加载您的应用程序。

但是,如您在问题中所述,您可以在响应有效负载后将通知设置为事件任务。假设您发送了正在进行的销售的推送通知,他们点击了通知本身,您可以注册任务以在选择时激活:

根据解析文档:

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
. . .
// Extract the notification data
NSDictionary *notificationPayload = launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey];

// Create a pointer to the Photo object
NSString *photoId = [notificationPayload objectForKey:@"p"];
PFObject *targetPhoto = [PFObject objectWithoutDataWithClassName:@"Photo"
objectId:photoId];

// Fetch photo object
[targetPhoto fetchIfNeededInBackgroundWithBlock:^(PFObject *object, NSError *error) {
// Show photo view controller
if (!error && [PFUser currentUser]) {
PhotoVC *viewController = [[PhotoVC alloc] initWithPhoto:object];
[self.navController pushViewController:viewController animated:YES];
}
}];
}

或者,您可以做的是拥有一个专用的“通知”或“消息”HUB 或 View Controller ,其中包含最近的通知列表供他们引用或选择

关于ios - 接收解析通知并通过应用程序图标打开应用程序以查看它而不是通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28084040/

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