最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

ios - Thread 1: "-[GUL_MyApp.AppDelegate pushRegistry:didUpdatePushCredentials:forType:]: unrecognized selector sent to

programmeradmin1浏览0评论

While updating to RN 0.78.0, as react native moved to swift from objective-cpp, after moving to swift, i am getting this error after build suceeds and app opens.

App crashes on the load and xcode gives this error:

Thread 1: "-[GUL_MyApp.AppDelegate pushRegistry:didUpdatePushCredentials:forType:]: unrecognized selector sent to instance

Here is my objective-cpp (before upgrade): AppDelegate.mm

#import "AppDelegate.h"
#import "RNCallKeep.h"

#import <React/RCTBundleURLProvider.h>

#import <PushKit/PushKit.h>
#import "RNVoipPushNotificationManager.h" 
@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  [RNVoipPushNotificationManager voipRegistration];

  self.moduleName = @"MyApp";
  self.initialProps = @{};


  return [super application:application didFinishLaunchingWithOptions:launchOptions];
}

- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
  return [self bundleURL];
}
 
- (NSURL *)bundleURL
{
#if DEBUG
  return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];
#else
  return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif
}


- (BOOL)application:(UIApplication *)application
continueUserActivity:(NSUserActivity *)userActivity
  restorationHandler:(void(^)(NSArray<id<UIUserActivityRestoring>> * __nullable restorableObjects))restorationHandler
{
  return [RNCallKeep application:application
           continueUserActivity:userActivity
             restorationHandler:restorationHandler];
}


/* Add PushKit delegate method */

// --- Handle updated push credentials
- (void)pushRegistry:(PKPushRegistry *)registry didUpdatePushCredentials:(PKPushCredentials *)credentials forType:(PKPushType)type {
  // Register VoIP push token (a property of PKPushCredentials) with server
  [RNVoipPushNotificationManager didUpdatePushCredentials:credentials forType:(NSString *)type];
}

- (void)pushRegistry:(PKPushRegistry *)registry didInvalidatePushTokenForType:(PKPushType)type
{
  // --- The system calls this method when a previously provided push token is no longer valid for use. No action is necessary on your part to reregister the push type. Instead, use this method to notify your server not to send push notifications using the matching push token.
}

// --- Handle incoming pushes
- (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(PKPushType)type withCompletionHandler:(void (^)(void))completion {

  // Process the received push
  [RNVoipPushNotificationManager didReceiveIncomingPushWithPayload:payload forType:(NSString *)type];


    [RNCallKeep reportNewIncomingCall: uuid
                             <rest of params>,
                withCompletionHandler: completion];
}


@end

AppDelegate.swift

import UIKit
import RNCallKeep
import React
import React_RCTAppDelegate
import ReactAppDependencyProvider
import PushKit
import RNVoipPushNotification


@main
class AppDelegate: RCTAppDelegate {
  override func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
    
    RNVoipPushNotificationManager.voipRegistration()
    self.moduleName = "MyApp"
    self.dependencyProvider = RCTAppDependencyProvider()
 
    self.initialProps = [:]
 
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
 
  override func sourceURL(for bridge: RCTBridge) -> URL? {
    self.bundleURL()
  }
 
  override func bundleURL() -> URL? {
#if DEBUG
    RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: "index")
#else
    Bundle.main.url(forResource: "main", withExtension: "jsbundle")
#endif
  }

  func application(
    _ application: UIApplication,
    continue userActivity: NSUserActivity,
    restorationHandler: @escaping ([Any]?) -> Void
) -> Bool {
    return RNCallKeep.application(
        application,
        continue: userActivity,
        restorationHandler: restorationHandler)
}
  
  func pushRegistry(_ registry: PKPushRegistry, didUpdate pushCredentials: PKPushCredentials, for type: PKPushType) {
      // Register VoIP push token (a property of PKPushCredentials) with server
      RNVoipPushNotificationManager.didUpdate(pushCredentials, forType: type.rawValue)
  }

  func pushRegistry(_ registry: PKPushRegistry, didInvalidatePushTokenFor type: PKPushType) {
      // --- The system calls this method when a previously provided push token is no longer valid for use. No action is necessary on your part to reregister the push type. Instead, use this method to notify your server not to send push notifications using the matching push token.
  }
  
  
  func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType, completion: @escaping () -> Void) {
    
          RNCallKeep.reportNewIncomingCall(
              <rest of params>,
              withCompletionHandler: completion)
      }
  }
  
}

While updating to RN 0.78.0, as react native moved to swift from objective-cpp, after moving to swift, i am getting this error after build suceeds and app opens.

App crashes on the load and xcode gives this error:

Thread 1: "-[GUL_MyApp.AppDelegate pushRegistry:didUpdatePushCredentials:forType:]: unrecognized selector sent to instance

Here is my objective-cpp (before upgrade): AppDelegate.mm

#import "AppDelegate.h"
#import "RNCallKeep.h"

#import <React/RCTBundleURLProvider.h>

#import <PushKit/PushKit.h>
#import "RNVoipPushNotificationManager.h" 
@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  [RNVoipPushNotificationManager voipRegistration];

  self.moduleName = @"MyApp";
  self.initialProps = @{};


  return [super application:application didFinishLaunchingWithOptions:launchOptions];
}

- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
  return [self bundleURL];
}
 
- (NSURL *)bundleURL
{
#if DEBUG
  return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];
#else
  return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif
}


- (BOOL)application:(UIApplication *)application
continueUserActivity:(NSUserActivity *)userActivity
  restorationHandler:(void(^)(NSArray<id<UIUserActivityRestoring>> * __nullable restorableObjects))restorationHandler
{
  return [RNCallKeep application:application
           continueUserActivity:userActivity
             restorationHandler:restorationHandler];
}


/* Add PushKit delegate method */

// --- Handle updated push credentials
- (void)pushRegistry:(PKPushRegistry *)registry didUpdatePushCredentials:(PKPushCredentials *)credentials forType:(PKPushType)type {
  // Register VoIP push token (a property of PKPushCredentials) with server
  [RNVoipPushNotificationManager didUpdatePushCredentials:credentials forType:(NSString *)type];
}

- (void)pushRegistry:(PKPushRegistry *)registry didInvalidatePushTokenForType:(PKPushType)type
{
  // --- The system calls this method when a previously provided push token is no longer valid for use. No action is necessary on your part to reregister the push type. Instead, use this method to notify your server not to send push notifications using the matching push token.
}

// --- Handle incoming pushes
- (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(PKPushType)type withCompletionHandler:(void (^)(void))completion {

  // Process the received push
  [RNVoipPushNotificationManager didReceiveIncomingPushWithPayload:payload forType:(NSString *)type];


    [RNCallKeep reportNewIncomingCall: uuid
                             <rest of params>,
                withCompletionHandler: completion];
}


@end

AppDelegate.swift

import UIKit
import RNCallKeep
import React
import React_RCTAppDelegate
import ReactAppDependencyProvider
import PushKit
import RNVoipPushNotification


@main
class AppDelegate: RCTAppDelegate {
  override func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
    
    RNVoipPushNotificationManager.voipRegistration()
    self.moduleName = "MyApp"
    self.dependencyProvider = RCTAppDependencyProvider()
 
    self.initialProps = [:]
 
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
 
  override func sourceURL(for bridge: RCTBridge) -> URL? {
    self.bundleURL()
  }
 
  override func bundleURL() -> URL? {
#if DEBUG
    RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: "index")
#else
    Bundle.main.url(forResource: "main", withExtension: "jsbundle")
#endif
  }

  func application(
    _ application: UIApplication,
    continue userActivity: NSUserActivity,
    restorationHandler: @escaping ([Any]?) -> Void
) -> Bool {
    return RNCallKeep.application(
        application,
        continue: userActivity,
        restorationHandler: restorationHandler)
}
  
  func pushRegistry(_ registry: PKPushRegistry, didUpdate pushCredentials: PKPushCredentials, for type: PKPushType) {
      // Register VoIP push token (a property of PKPushCredentials) with server
      RNVoipPushNotificationManager.didUpdate(pushCredentials, forType: type.rawValue)
  }

  func pushRegistry(_ registry: PKPushRegistry, didInvalidatePushTokenFor type: PKPushType) {
      // --- The system calls this method when a previously provided push token is no longer valid for use. No action is necessary on your part to reregister the push type. Instead, use this method to notify your server not to send push notifications using the matching push token.
  }
  
  
  func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType, completion: @escaping () -> Void) {
    
          RNCallKeep.reportNewIncomingCall(
              <rest of params>,
              withCompletionHandler: completion)
      }
  }
  
}
Share Improve this question asked Mar 3 at 9:36 Irfan waniIrfan wani 5,0982 gold badges29 silver badges48 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Appdelegate needs to inherit PKPushRegistryDelegate too.

Modified it as:

class AppDelegate: RCTAppDelegate, PKPushRegistryDelegate

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论