react-native PushNotificationIos编译错误

时间:2018-02-14 00:29:38

标签: ios objective-c react-native react-native-push-notification

TL; DR如何将UNNotificationRequest与react-native一起使用?

尝试在react-native中实现推送通知处理。在react-native文档中,它说我应该将以下内容添加到我的AppDelegate.m中:

// Required to register for notifications
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
  [RCTPushNotificationManager didRegisterUserNotificationSettings:notificationSettings];
}
// Required for the register event.
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
  [RCTPushNotificationManager didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}
// Required for the notification event. You must call the completion handler after handling the remote notification.
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
                                                      fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
  [RCTPushNotificationManager didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
}
// Required for the registrationError event.
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
  [RCTPushNotificationManager didFailToRegisterForRemoteNotificationsWithError:error];
}
// Required for the localNotification event.
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
  [RCTPushNotificationManager didReceiveLocalNotification:notification];
}

问题是本地通知方法给我一个构建错误:

'UILocalNotification' is deprecated: first deprecated in iOS 10.0 - Use UserNotifications Framework's UNNotificationRequest

所以这很容易修复,我只需要使用UNNotificationRequest,对吧?我的问题是,我该如何导入它? doc页面如下所示:

https://developer.apple.com/documentation/usernotifications/unnotificationrequest

他们认为我知道如何导入它。我没有。我如何知道如何做到这一点?

PS:请不要急。只对象。 react-native使用objc。

0 个答案:

没有答案
相关问题