Skip to content

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

Open
@Irfanwani

Description

@Irfanwani

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)
      }
  }
  
}


I Don't have much knowlege about swift or objective cpp, but I think in the above case, we maybe missing the bridging header file. Please correct me if i am wrong.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions