2017-04-27 11:18:12 +00:00
# iOS Installation
2017-03-02 12:50:09 +00:00
2017-06-13 16:27:35 +00:00
## 1) Setup GoogleService-Info.plist
2017-06-13 15:18:12 +00:00
Setup the `GoogleService-Info.plist` file by following the instructions and adding it to the root of your project at `ios/[YOUR APP NAME]/GoogleService-Info.plist` [here ](https://firebase.google.com/docs/ios/setup#add_firebase_to_your_app ).
2017-03-28 08:22:25 +00:00
2017-04-27 11:18:12 +00:00
### 1.1) Initialisation
2017-04-06 12:11:43 +00:00
Make sure you've added the following to the top of your `ios/[YOUR APP NAME]]/AppDelegate.m` file:
2017-03-02 12:50:09 +00:00
2017-03-28 08:22:25 +00:00
`#import <Firebase.h>`
2017-03-02 12:50:09 +00:00
2017-06-13 15:18:12 +00:00
and this to the `didFinishLaunchingWithOptions:(NSDictionary *)launchOptions` method before the `return` statement:
2017-03-28 08:22:25 +00:00
`[FIRApp configure];`
2017-06-20 09:17:56 +00:00
## 2) Setup RNFirebase
2017-05-03 07:40:15 +00:00
2017-06-20 09:17:56 +00:00
Unfortunately, due to the fact that Firebase is much easier to setup using Cocoapods, *we do not recommend* `react-native link` as it is not customisable enough for our needs and we have had numerous problems reported.
2017-03-28 08:22:25 +00:00
2017-06-13 15:18:12 +00:00
### 2.0) If you don't already have Cocoapods set up
Follow the instructions to install Cocoapods and create your Podfile [here ](https://firebase.google.com/docs/ios/setup#add_the_sdk ).
2017-03-02 12:50:09 +00:00
2017-06-30 13:18:10 +00:00
**NOTE: The Podfile needs to be initialised in the `ios` directory of your project. Make sure to update cocoapods libs first by running `pod update` **
2017-03-28 08:22:25 +00:00
2017-06-13 16:22:41 +00:00
#### Troubleshooting
1) When running `pod install` you may encounter an error saying that a `tvOSTests` target is declared twice. This appears to be a bug with `pod init` and the way that react native is set up.
2017-05-03 07:40:15 +00:00
2017-06-13 16:22:41 +00:00
**Resolution:**
- Open your Podfile
- Remove the duplicate `tvOSTests` target nested within the main project target
- Re-run `pod install` .
2017-04-27 11:18:12 +00:00
2017-06-13 16:22:41 +00:00
2) When running `pod install` you may encounter a number of warnings relating to `target overrides 'OTHER_LDFLAGS'` .
2017-03-27 11:38:33 +00:00
2017-06-13 16:22:41 +00:00
**Resolution:**
- Open Xcode
- Select your project
- For each target:
-- Select the target
-- Click Build settings
-- Search for `other linker flags`
-- Add `$(inherited)` as the top line if it doesn't already exist
- Re-run `pod install`
2017-03-27 11:38:33 +00:00
2017-06-13 16:22:41 +00:00
3) When running `pod install` you may encounter a warning that a default iOS platform has been assigned. If you wish to specify a different minimum version:
2017-03-27 11:38:33 +00:00
2017-06-13 16:22:41 +00:00
**Resolution**
- Open your Podfile
- Uncomment the `# platform :ios, '9.0'` line by removing the `#` character
- Change the version as required
2017-03-27 11:38:33 +00:00
2017-06-13 15:18:12 +00:00
### 2.1) Add the required pods
2017-06-13 16:22:41 +00:00
Simply add the following to your `Podfile` either at the top level, or within the main project target:
2017-03-28 08:22:25 +00:00
```ruby
# Required by RNFirebase
pod 'Firebase/Core'
2017-06-16 12:45:45 +00:00
pod 'RNFirebase', :path => '../node_modules/react-native-firebase'
# [OPTIONAL PODS] - comment out pods for firebase products you won't be using.
pod 'Firebase/AdMob'
pod 'Firebase/Analytics'
pod 'Firebase/Auth'
2017-03-28 08:22:25 +00:00
pod 'Firebase/Crash'
pod 'Firebase/Database'
pod 'Firebase/DynamicLinks'
pod 'Firebase/Messaging'
pod 'Firebase/RemoteConfig'
pod 'Firebase/Storage'
```
2017-06-13 16:22:41 +00:00
If you are new to Cocoapods or do not already have React installed as a pod, then add Yoga and React to your `Podfile` as follows:
2017-03-28 08:22:25 +00:00
```ruby
2017-06-13 15:18:12 +00:00
pod "Yoga", :path => "../node_modules/react-native/ReactCommon/yoga"
pod 'React', :path => '../node_modules/react-native', :subspecs => [
2017-06-13 16:22:41 +00:00
'BatchedBridge', # Required For React Native 0.45.0+
2017-06-13 15:18:12 +00:00
'Core',
# Add any other subspecs you want to use in your project
]
2017-03-28 08:22:25 +00:00
```
2017-06-13 16:22:41 +00:00
Run `pod install` .
2017-05-03 07:40:15 +00:00
**NOTE: You need to use the `ios/[YOUR APP NAME].xcworkspace` instead of the `ios/[YOUR APP NAME].xcproj` file from now on.**
2017-05-02 08:36:17 +00:00
2017-06-13 16:22:41 +00:00
#### Troubleshooting
1) You receive an error `No podspec found for 'RNFirebase'`
**Resolution**
- Run `npm install --save react-native-firebase` from the root of your project
2017-05-02 08:36:17 +00:00
## 3) Cloud Messaging (optional)
If you plan on using [Firebase Cloud Messaging ](https://firebase.google.com/docs/cloud-messaging/ ) then, you need to:
**NOTE: FCM does not work on the iOS simulator, you must test is using a real device. This is a restriction enforced by Apple for some unknown reason.**
### 3.1) Set up certificates
Follow the instructions at https://firebase.google.com/docs/cloud-messaging/ios/certs
### 3.2) Enable capabilities
In Xcode, enable the following capabilities:
1) Push Notifications
2017-05-11 08:54:23 +00:00
2) Background modes > Remote notifications
2017-05-02 08:36:17 +00:00
### 3.3) Update `AppDelegate.h`
Add the following import:
`@import UserNotifications;`
Change the interface descriptor to:
`@interface AppDelegate : UIResponder <UIApplicationDelegate,UNUserNotificationCenterDelegate>`
### 3.4) Update `AppDelegate.m`
Add the following import:
`#import "RNFirebaseMessaging.h"`
Add the following to the `didFinishLaunchingWithOptions:(NSDictionary *)launchOptions` method after `[FIRApp Configure]` :
`[[UNUserNotificationCenter currentNotificationCenter] setDelegate:self];`
Add the following methods:
2017-05-02 09:56:33 +00:00
```objectivec
2017-05-02 08:36:17 +00:00
-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification * )notification {
[RNFirebaseMessaging didReceiveLocalNotification:notification];
}
2017-05-30 09:04:27 +00:00
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(nonnull NSDictionary * )userInfo {
[RNFirebaseMessaging didReceiveRemoteNotification:userInfo];
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(nonnull NSDictionary * )userInfo
2017-06-16 12:45:45 +00:00
fetchCompletionHandler:(nonnull void (^)(UIBackgroundFetchResult))completionHandler{
2017-05-02 08:36:17 +00:00
[RNFirebaseMessaging didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
}
```
2017-05-30 09:04:27 +00:00
### 3.5) Debugging
If you're having problems with messages not being received, check out the following blog post for help:
https://firebase.googleblog.com/2017/01/debugging-firebase-cloud-messaging-on.html