使用 PushNotificationIOS 时没有已知的选择器类方法

Posted

技术标签:

【中文标题】使用 PushNotificationIOS 时没有已知的选择器类方法【英文标题】:No known class method for selector while using PushNotificationIOS 【发布时间】:2016-01-25 05:26:20 【问题描述】:

我正在尝试让推送通知在我的 React Native ios 应用程序中工作。我正在关注教程PushNotificationsIOS。我也手动链接了库。

在AppDelegate.m文件中看起来如下,

/**
 * Copyright (c) 2015-present, Facebook, Inc.
 * All rights reserved.
 *
 * This source code is licensed under the BSD-style license found in the
 * LICENSE file in the root directory of this source tree. An additional grant
 * of patent rights can be found in the PATENTS file in the same directory.
 */
#import "RCTPushNotificationManager.h"

#import "AppDelegate.h"

#import "RCTRootView.h"

@implementation AppDelegate

// 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.
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)notification

  [RCTPushNotificationManager didReceiveRemoteNotification:notification];


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

  NSURL *jsCodeLocation;

  /**
   * Loading javascript code - uncomment the one you want.
   *
   * OPTION 1
   * Load from development server. Start the server from the repository root:
   *
   * $ npm start
   *
   * To run on device, change `localhost` to the IP address of your computer
   * (you can get this by typing `ifconfig` into the terminal and selecting the
   * `inet` value under `en0:`) and make sure your computer and iOS device are
   * on the same Wi-Fi network.
   */

  //jsCodeLocation = [NSURL URLWithString:@"http://172.16.2.173:8081/index.ios.bundle?platform=ios&dev=true"];

  jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.ios.bundle?platform=ios&dev=true"];

  /**
   * OPTION 2
   * Load from pre-bundled file on disk. The static bundle is automatically
   * generated by "Bundle React Native code and images" build step.
   */

  //jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];

  RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
                                                      moduleName:@"myapp"
                                               initialProperties:nil
                                                   launchOptions:launchOptions];

  self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  UIViewController *rootViewController = [UIViewController new];
  rootViewController.view = rootView;
  self.window.rootViewController = rootViewController;
  [self.window makeKeyAndVisible];
  return YES;


@end

但是构建失败并出现错误,

No known class method for selector 'didRegisterUserNotificationSettings:'
No known class method for selector 'didRegisterForRemoteNotificationsWithDeviceToken:'
No known class method for selector 'didReceiveRemoteNotification:'

这是为什么?如何解决这个问题?


PS:注意

找到了一个替代方案,效果很好。 Apple Push Notification Services in iOS 6 Tutorial

【问题讨论】:

你想使用另一个教程吗? @VvkAghera 如果可用,请指定任何内容。 关注我的回答。在您的代码片段中,我没有发现任何问题。如需更多帮助,请联系我 @VvkAghera 它确实帮助了我。谢谢你。 :) @LukeDubert 我用另一个教程更新了这个问题。 AppDelegate 代码已更改。 【参考方案1】:

请遵循非常简单的 raywenderlich 教程。 APNS Tutorial 希望对您有所帮助。

【讨论】:

以上是关于使用 PushNotificationIOS 时没有已知的选择器类方法的主要内容,如果未能解决你的问题,请参考以下文章

PushNotificationIOS.presentLocalNotification() 在 react-native 中不起作用

使用 PushNotificationIOS 时没有已知的选择器类方法

如何使用 react-native 的 PushNotificationIOS.getInitialNotification

在 React Native 的 iPhone 设置上手动禁用后如何检测 PushNotificationIOS 状态?

React Native PushNotificationIOS:CUICatalog:提供的资产名称无效:(null)

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