在 React Native 前台设置 PushNotificationIOS 时发出警告

Vin*_*ius 2 objective-c ios react-native react-native-ios

在 IOS 上设置前台推送通知时,我在 Xcode 上收到以下警告:

Assigning to 'id<UNUserNotificationCenterDelegate> _Nullable' 
from incompatible type 'AppDelegate *const __strong'
Run Code Online (Sandbox Code Playgroud)

此警告出现在此代码段的最后一行:

// Define UNUserNotificationCenter
  UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
  center.delegate = self;
Run Code Online (Sandbox Code Playgroud)

我的应用程序编译并按预期运行。我没有使用objective-c的经验,所以我不知道这是关于什么的。我该如何解决?

Mik*_*ona 5

我遇到了同样的问题并通过添加UNUserNotificationCenterDelegate到我的 AppDelegate 接口来解决它:

@interface AppDelegate : UIResponder <UIApplicationDelegate,UNUserNotificationCenterDelegate>
Run Code Online (Sandbox Code Playgroud)

  • 还将 #import &lt;UserNotifications/UserNotifications.h&gt; 添加到 AppDelegate.h (6认同)