Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Irfanwani opened this issue Mar 2, 2025 · 2 comments

Comments

@Irfanwani
Copy link
Contributor

Irfanwani commented Mar 2, 2025

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.

@Irfanwani
Copy link
Contributor Author

I think i am wrong about bridging headers. They just expose the code which is same as importing it directly in swift file.
I tried it out and that is what i understood from the implementation.

@Irfanwani
Copy link
Contributor Author

Irfanwani commented Mar 3, 2025

Appdelegate needs to inherit PKPushRegistryDelegate too.

Modified it as:

class AppDelegate: RCTAppDelegate, PKPushRegistryDelegate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant