-
Notifications
You must be signed in to change notification settings - Fork 8
Integration while using Expo tools
Olga Koroleva edited this page Jan 15, 2025
·
2 revisions
Resolving the error: ExpoDevLauncherReactDelegateHandler.swift:43: Fatal error: The
UIApplication.shared.delegate is not a RCTAppDelegate instance"
If you encounter this or a similar error while running your application on iOS with Expo tools, you can resolve it by making the following change:
Instead of using [MobileMessagingPluginApplicationDelegate install];
in the AppDelegate.mm
directly call the corresponding MobileMessaging SDK methods to handle the device token and push notifications when they are received.
To implement it follow the steps:
-
Create an Objective-C wrapper for MobileMessaging SDK methods to be able to call them from the Objective-C++ code which is
AppDelegate.mm
:
//
// MobileMessagingCustomWrapper.h
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface MobileMessagingCustomWrapper : NSObject
+ (void)didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken;
+ (void)didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler;
+ (BOOL)isMessagePayloadCorrect:(NSDictionary *)payload;
@end
NS_ASSUME_NONNULL_END
//
// MobileMessagingCustomWrapper.m
//
#import "MobileMessagingCustomWrapper.h"
@import MobileMessaging;
@implementation MobileMessagingCustomWrapper
+ (void)didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
[MobileMessaging didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}
+ (void)didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
[MobileMessaging didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
}
+ (BOOL)isMessagePayloadCorrect:(NSDictionary *)payload {
return [MM_MTMessage isCorrectPayload:payload];
}
@end
-
Replace
[MobileMessagingPluginApplicationDelegate install]
in theAppDelegate.mm
:
#import "AppDelegate.h"
...
// Not needed any more
//#import <MobileMessaging/MobileMessagingPluginApplicationDelegate.h>
// Added the import of the wrapper's header
#import "MobileMessagingCustomWrapper.h"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Not needed if token and received message provided to the MobileMessaging SDK via calling MobileMessagingCustomWrapper methods
// [MobileMessagingPluginApplicationDelegate install];
...
return YES;
}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
[MobileMessagingCustomWrapper didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
if ([MobileMessagingCustomWrapper isMessagePayloadCorrect:userInfo]) {
[MobileMessagingCustomWrapper didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
} else {
completionHandler(UIBackgroundFetchResultNoData);
}
}
@end
If you have any questions or suggestions, feel free to send an email to [email protected] or create an issue.
- Library events
- Server errors
- Users and installations
- Messages and notifications management
- Inbox
- Privacy settings
- In‐app chat
- WebRTC Calls and UI
- Migration guides
- JSON Web Token (JWT) structure and generation example