gpt4 book ai didi

ios - 如何从Apple Push Notifications获取userInfo

转载 作者:行者123 更新时间:2023-12-01 22:18:15 26 4
gpt4 key购买 nike

我的企业应用程序正在使用Apple Push Notifications,并且在大多数情况下都可以正常工作。我想做的是通过userDidRespondToPush之外的方法从通知中获取用户信息。

如果有通知等待,系统会在iPhone主屏幕上的图标上放置徽章。如果用户自己响应通知,则该应用将触发userRespondsToPush。但是,如果用户没有滑动通知并正常启动应用程序,则可以通过点击显示带有徽章的应用程序图标来使应用程序响应,就像用户确实滑动了通知一样。这意味着我将需要使用userInfo以外的方法来获取userDidRespondToPush,以便应用程序知道向用户显示哪些信息。

推送通知对我来说还很新,但是我很幸运,它可以正常工作。我只需要这一小功能即可工作。

最佳答案

如果您的应用程序支持iOS 10及更高版本,则您应该能够使用UNUserNotificationCenter类检索待处理的通知。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[UNUserNotificationCenter currentNotificationCenter] getPendingNotificationRequestsWithCompletionHandler:^(NSArray<UNNotificationRequest *> * _Nonnull requests) {
for (UNNotificationRequest *request in requests) {
NSDictionary *userInfo = request.content.userInfo;
NSLog(@"push user info: %@", userInfo);
// Handle the payload here.
}
}];
return YES;
}

关于ios - 如何从Apple Push Notifications获取userInfo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49929606/

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