Allow APN token input on Register()
Closed this issue · 8 comments
Hi,
Firebase Messaging actually provides an APN token creation and integration with 3rd party push notification providers:
https://rnfirebase.io/messaging/server-integration
// If using other push notification providers (ie Amazon SNS, etc)
// you may need to get the APNs token instead for iOS:
if(Platform.OS == 'ios') { messaging().getAPNSToken().then(token => { return addTokenToThirdParty; }); }
However, with Pushy it seems that I cannot register an APN token myself. Is it possible for Pushy to provide a feature whereby it allows APN tokens from Firebase, so that we can use Firebase and Pushy in the same app together?
Hi @causztic,
We'd be glad to assist with your inquiry.
Both the Pushy iOS SDK and the Firebase iOS SDK use method swizzling to hook into the AppDelegate
APNs token registration methods to capture the APNs token, which causes a conflict when both SDKs are used in the same project.
To use both FCM and Pushy in the same iOS project:
-
Please disable swizzling in the FCM SDK by adding the flag
FirebaseAppDelegateProxyEnabled
to yourInfo.plist
and setting it toNO
as described here:
https://firebase.google.com/docs/cloud-messaging/ios/client#method_swizzling_in -
Follow the instructions here to implement the
didRegisterForRemoteNotificationsWithDeviceToken
method manually in your React Native project'sAppDelegate
, calling the FCM method as documented:
https://firebase.google.com/docs/cloud-messaging/ios/client#token-swizzle-disabled -
In the same implementation of
didRegisterForRemoteNotificationsWithDeviceToken
, add an invocation to pass the token the Pushy iOS SDK. Final code could look like this:
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
// Pass token to Firebase
Messaging.messaging().apnsToken = deviceToken
// Call Pushy SDK didRegisterForRemoteNotificationsWithDeviceToken:deviceToken method
Pushy(UIApplication.shared).application(application, didRegisterForRemoteNotificationsWithDeviceToken:deviceToken)
}
Good day,
Can you tell me how this config will look like in React Native in the AppDelegate.m (Objective-C) file?
Hi @XfortunaX,
Simply open your React Native iOS project in Xcode (ios/.xcodeproj
file), and edit the AppDelegate.m
inside it, adding the following method override:
- (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
// Pass token to Firebase
[FIRMessaging messaging].APNSToken = deviceToken;
// Pass token to Pushy
Pushy* pushy = [[Pushy alloc]init:[UIApplication sharedApplication]];
[pushy application:application, didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}
Thanks for your support, but this code gives an error: Use of undeclared identifier 'Pushy'
I used the connection guide - https://pushy.me/docs/additional-platforms/react-native
And added the following lines
#import <PushyModule.h>
// Initialize Pushy Module
[PushyModule didFinishLaunchingWithOptions: launchOptions];
What needs to be added for this code to work?
Hi @XfortunaX,
Please use the following import
statement to access the Pushy
class in React Native:
#if __has_include(<PushyRN/PushyRN-Swift.h>)
#import <PushyRN/PushyRN-Swift.h>
#else
#import "PushyRN-Swift.h"
#endif
Hi,
I have added these imports to the top of AppDelegate.m next to
#import <PushyModule.h>
but gives an import error - 'PushyRN-Swift.h' file not found
I saw that these imports are used inside the module, but they are not available here ...
Hi @XfortunaX,
Please try this instead (and remove the import
statement suggested previously:
- Use the following override of
didRegisterForRemoteNotificationsWithDeviceToken
in your project'sAppDelegate.m
:
- (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
// Pass token to Firebase
[FIRMessaging messaging].APNSToken = deviceToken;
// Pass token to Pushy
[PushyModule didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}
- Edit
Libraries/PushyRN.xcodeproj/PushyModule.h
, replacing it with the following:
#import <React/RCTBridgeModule.h>
#import <React/RCTEventEmitter.h>
@interface PushyModule : RCTEventEmitter <RCTBridgeModule>
+ (void)didFinishLaunchingWithOptions:(NSDictionary *)launchOptions;
+ (void)didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)token;
@end
- Edit
Libraries/PushyRN.xcodeproj/PushyModule.m
, adding the following method inside:
+ (void)didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)token {
[pushy application:[UIApplication sharedApplication] didRegisterForRemoteNotificationsWithDeviceToken:token];
}