expo-firebase-links
expo-firebase is still in RC and therefore subject to breaking changings. Be sure to run
yarn upgrade
andcd ios; pod install
when upgrading.
expo-firebase-links
exposes the native Firebase Dynamic Linking API. You can create and share links for both iOS and Android.
Installation
Firstly, you need to install the package from npm
registry.
npm install expo-firebase-links
or yarn add expo-firebase-links
iOS
Cocoapods
If you're using Cocoapods, add the dependency to your Podfile
:
pod 'EXFirebaseLinks', path: '../node_modules/expo-firebase-links/ios'
and run pod install
.
Common Setup
Now follow the setup instructions in the docs.
Update your AppDelegate.m file:
Import RN Firebase Links header file:
Add the following to the didFinishLaunchingWithOptions method before [FIRApp Configure]
:
.deepLinkURLScheme = CUSTOM_URL_SCHEME;
where
CUSTOM_URL_SCHEME
is the custom URL scheme you defined in your Xcode project.
Add the following inside the @implementation AppDelegate
annotation:
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary<NSString *, id> *)options - (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray *))restorationHandler
You might run into situation when you need to handle more than one link configuration i.e. when using Facebook SDK to handle push notification / login links if that is the case you can perform check below
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
Android
-
Append the following lines to
android/settings.gradle
:include ':expo-firebase-links'project(':expo-firebase-links').projectDir = new File(rootProject.projectDir, '../node_modules/expo-firebase-links/android')and if not already included
include ':expo-core'project(':expo-core').projectDir = new File(rootProject.projectDir, '../node_modules/expo-core/android')include ':expo-firebase-app'project(':expo-firebase-app').projectDir = new File(rootProject.projectDir, '../node_modules/expo-firebase-app/android') -
Insert the following lines inside the dependencies block in
android/app/build.gradle
:api project(':expo-firebase-links')and if not already included
api project(':expo-core')api project(':expo-firebase-app') -
Include the module in your expo packages:
./android/app/src/main/java/host/exp/exponent/MainActivity.java
/** At the top of the file.* This is automatically imported with Android Studio, but if you are in any other editor you will need to manually import the module.*/// This should be here for all Expo Firebase features.// Later in the file...@Overridepublic List<Package> {// Here you can add your own packages.return Arrays.<Package>;}
Usage
;;; // API can be accessed with: firebase.links(); Component async { // ... initialize firebase app const link = 'https://example.com?param1=foo¶m2=bar' 'abc123.app.goo.gl' android ios; try // Create a url that you can share with others. const url = await firebaselinks; catch message // An Error was thrown. console; } { return <View />; }