OGeek|极客世界-中国程序员成长平台

标题: ios - 使用 PushNotificationIOS 时没有已知的选择器类方法 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 13:44
标题: ios - 使用 PushNotificationIOS 时没有已知的选择器类方法

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

PushNotificationIOS Library

在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)applicationUIApplication *)application didRegisterUserNotificationSettingsUIUserNotificationSettings *)notificationSettings
{
  [RCTPushNotificationManager didRegisterUserNotificationSettings:notificationSettings];
}
// Required for the register event.
- (void)applicationUIApplication *)application didRegisterForRemoteNotificationsWithDeviceTokenNSData *)deviceToken
{
  [RCTPushNotificationManager didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}
// Required for the notification event.
- (void)applicationUIApplication *)application didReceiveRemoteNotificationNSDictionary *)notification
{
  [RCTPushNotificationManager didReceiveRemoteNotification:notification];
}

- (BOOL)applicationUIApplication *)application didFinishLaunchingWithOptionsNSDictionary *)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



Best Answer-推荐答案


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

关于ios - 使用 PushNotificationIOS 时没有已知的选择器类方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34985677/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (https://ogeek.cn/) Powered by Discuz! X3.4