Skip to content

Instantly share code, notes, and snippets.

@brickpop
Last active February 1, 2017 23:48
Show Gist options
  • Save brickpop/e8c41c3009628910c859a07b8bcd38c5 to your computer and use it in GitHub Desktop.
Save brickpop/e8c41c3009628910c859a07b8bcd38c5 to your computer and use it in GitHub Desktop.
FCM for iOS HowTo
# Extra info:
# https://firebase.google.com/docs/ios/setup
react-native init Twins
cd Twins
react-native run-ios
yarn add react-native-fcm
react-native link react-native-fcm
cd ios
pod init
Add the following line inside the Podfile
>> pod 'Firebase/Messaging'
pod install
open ios/Twins.xcworkspace
Build Settings > Header search path > add:
>> '$(SRCROOT)/../node_modules/react-native-fcm/ios'
AppDelegate.h (update)
@import UserNotifications;
@interface AppDelegate : UIResponder <UIApplicationDelegate,UNUserNotificationCenterDelegate>
AppDelegats.m (update)
#import "RNFIRMessaging.h"
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//...
[FIRApp configure];
[[UNUserNotificationCenter currentNotificationCenter] setDelegate:self];
// ...
}
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler
{
[RNFIRMessaging willPresentNotification:notification withCompletionHandler:completionHandler];
}
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler
{
[RNFIRMessaging didReceiveNotificationResponse:response withCompletionHandler:completionHandler];
}
//You can skip this method if you don't want to use local notification
-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
[RNFIRMessaging didReceiveLocalNotification:notification];
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(nonnull NSDictionary *)userInfo fetchCompletionHandler:(nonnull void (^)(UIBackgroundFetchResult))completionHandler{
[RNFIRMessaging didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
}
----
XCode
Select your project Capabilities and enable Keychan Sharing and Background Modes > Remote notifications.
In Xcode menu bar, select Product > Scheme > Manage schemes.
Select your project name Scheme then click on the minus sign ― in the bottom left corner, then click on the plus sign + and rebuild your project scheme.
Twins scheme > Build >
- Uncheck "Parallelize Builds"
- Add "React" and put it first
- Uncheck Analyze in Twins and React
# https://twitter.com/skellock/status/818813810781908992
----
- Inside your project in the Firebase console, select the gear icon, select Project Settings, and then select the Cloud Messaging tab.
- Select the Upload Certificate button for your development certificate, your production certificate, or both. At least one is required.
- For each certificate, select the .p12 file, and provide the password, if any. Make sure the bundle ID for this certificate matches the bundle ID of your app. Select Save.
----
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment