且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从 Apple 推送通知中获取用户信息

更新时间:2023-12-03 16:18:34

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

If your application supports iOS 10 and above, then you should be able to retrieve pending notifications using the UNUserNotificationCenter class.

- (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;
}