1818
19192 . Getting started
2020 + [ Installation] ( #installation )
21- + [ Updating from an earlier SDK version or starting with v. 3 .0.0] ( #updating-from-an-earlier-version-or-starting-with-v300 )
21+ + [ Updating from an earlier SDK version or starting with v. 4 .0.0] ( #updating-from-an-earlier-version-or-starting-with-v400 )
2222 + [ Register for Branch key] ( #register-your-app )
2323 + [ Project setup] ( #setup )
2424 + [ Example apps] ( #example-apps )
25+ + [ Tutorial app] ( #tutorial-app )
2526
26273 . Branch general methods
2728 + [ Register a subscriber] ( #register-a-subscriber )
54556 . General support
5556 + [ Troubleshooting] ( #troubleshooting )
5657
58+ [ Manual branch.json installation ] : ./docs/branch.json.md#manual-integration-without-react-native-link
59+ [ Version 3.0 ] : ./docs/version-3.md
60+ [ Version 4.0 ] : ./docs/version-4.md
61+ [ webview_example ] : ./examples/webview_example
62+ [ webview_example_native_ios ] : ./examples/webview_example_native_ios
63+ [ webview_tutorial ] : ./examples/webview_tutorial
64+ [ Tutorial app ] : #tutorial-app
65+
5766## Installation
5867
59- Note that the ` react-native-branch ` module requires ` react-native ` >= 0.40.
68+ Note that version 4.0 of the ` react-native-branch ` module requires
69+ ` react-native ` >= 0.60. If you are using RN < 0.60, please see the instructions
70+ for [ Version 3.0] of 'react-native-branch'.
6071
61721 . ` yarn add react-native-branch `
62- 2 . (Optional) Add a branch.json file to the root of your app project. See https://rnbranch.app.link/branch-json .
63- 3 . ` react-native link react-native-branch `
64- 4 . Install the native Branch SDK using [ CocoaPods] ( ./docs/cocoapods.md ) or [ Carthage] ( ./docs/carthage.md ) .
65- 5 . Follow the [ setup instructions] ( #setup ) .
73+ 2 . ` cd ios; pod install `
74+ 3 . Follow the [ setup instructions] ( #setup ) .
75+ 4 . (Optional) Add branch.json to your project. See [ Manual branch.json installation] .
6676
6777** Note:** This SDK currently does not work in projects using NPM instead of yarn.
6878See #433 . The RN toolchain will use yarn by default. Please use
6979` yarn add react-native-branch ` to add the SDK to your project.
7080
81+ See the [ Tutorial app] for a step-by-step walkthrough of integrating Branch in
82+ an existing RN 0.60 app.
83+
7184___
7285
73- ### Updating from an earlier version or starting with v3.0.0
74-
75- The native SDKs are no longer bundled into this module. The native Android SDK
76- will be installed from Maven via Gradle. You must add the native Branch iOS SDK
77- to your project either using [ CocoaPods] ( ./docs/cocoapods.md ) or [ Carthage] ( ./docs/carthage.md ) .
78-
79- To fix a longstanding build issue with Android, it is necessary to take the
80- native Branch Android SDK from Maven rather than from the react-native-branch
81- module, starting with version 3.0.0. This now happens transparently via Gradle.
82- If you previously added ` implementation fileTree(dir: 'libs', include: ['*.jar']) `
83- to your ` app/build.gradle ` only for React Native Branch, you may remove it,
84- unless it is now used by other code.
85-
86- Remove any direct reference to ` io.branch.sdk.android:library ` in your dependencies,
87- e.g. ` io.branch.sdk.android:library:3.1.1 ` . This has the potential to cause
88- conflicts. This module imports the Branch SDK directly.
89-
90- The result in your ` app/build.gradle ` should be something like
91- ``` gradle
92- dependencies {
93- implementation project(':react-native-branch')
94- implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
95- implementation "com.facebook.react:react-native:+" // From node_modules
96- }
86+ ### Updating from an earlier version or starting with v4.0.0
87+
88+ Please see [ Version 4.0] for more details.
89+
90+ - react-native >= 0.60 is required
91+ - AndroidX is required
92+ - CocoaPods is required
93+ - Autolinking is supported
94+
95+ #### New installations
96+
97+ (Optional)
98+ Add branch.json to your project. See [ Manual branch.json installation] .
99+
100+ #### Updating
101+
102+ Once you have updated to RN 0.60 and version 4.0 of this SDK, run:
103+
104+ ``` bash
105+ react-native unlink react-native-branch
97106```
98107
99- If you're using an older version of Gradle, you may need ` compile ` instead of
100- ` implementation ` .
108+ This will not affect branch.json once you have updated to 4.0. The postunlink
109+ hook that removed it from a project no longer runs. If you have added it to
110+ your project previously, it will remain.
101111
102- It is recommended to replace ` Branch.getAutoInstance ` in your ` Application.onCreate `
103- method with ` RNBranchModule.getAutoInstance ` . This is required in order to set Branch
104- keys in the ` branch.json ` file.
112+ ##### Android
105113
106- ``` java
114+ It is no longer necessary to make use of RNBranchPackage in
115+ MainApplication.java. The whole of your getPackages() method should look like
116+ this with RN 0.60:
117+
118+ ``` Java
107119@Override
108- public void onCreate() {
109- super . onCreate();
110- SoLoader . init(this , /* native exopackage */ false );
111- // Replace Branch.getAutoInstance(this); with:
112- RNBranchModule . getAutoInstance(this );
120+ protected List<ReactPackage > getPackages() {
121+ return new PackageList (this ). getPackages();
113122}
114123```
115124
116- If you are not already using the React pod to build your app, it will
117- be necessary to [ convert your Xcode project] ( ./docs/convert-to-react-pod.md ) .
125+ ##### iOS
126+
127+ ** iOS imports have changed**
128+ Note that ` use_frameworks! ` currently does not work with RN 0.60. See
129+ https://github.com/facebook/react-native/issues/25349 . Regardless of
130+ that setting, in Objective-C, use:
131+
132+ ``` Obj-C
133+ #import < RNBranch/RNBranch.h>
134+ ```
135+
136+ Without ` use_frameworks! ` in your Podfile, you cannot import native modules
137+ directly in Swift. Once that RN bug is fixed, you can use:
118138
119- The ` cached_initial_event ` key in the ` params ` returned in the ` subscribe `
120- callback has been renamed to ` +rn_cached_initial_event ` .
139+ ``` Swift
140+ import RNBranch
141+ ```
142+
143+ in Swift source code. For now it is possible to use the Objective-C import in a
144+ Swift bridging header. See [ webview_example_native_ios] for an example
145+ of a Swift app that imports RNBranch via a bridging header while also using
146+ Swift pods.
121147
122148___
123149
@@ -139,17 +165,8 @@ Modify your AppDelegate as follows:
139165#### Objective-C
140166In AppDelegate.m
141167
142- Note that if you are not using the React pod, or if you don't have ` use_frameworks! ` in your Podfile, and your
143- AppDelegate is written in Objective-C, you should replace
144- ` @import react_native_branch; ` with ` #import <react-native-branch/RNBranch.h> ` .
145- Also note that CocoaPods 1.7.0 breaks iOS builds using the react-native-branch pod.
146- Please update to version 1.7.1 instead. See #461 .
147-
148168``` objective-c
149- @import react_native_branch; // at the top
150-
151- // Use this instead if are not using the React pod or you don't use_frameworks! in your Podfile.
152- // #import <react-native-branch/RNBranch.h>
169+ #import < RNBranch/RNBranch.h> // at the top
153170
154171// Initialize the Branch Session at the top of existing application:didFinishLaunchingWithOptions:
155172- (BOOL )application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
@@ -200,15 +217,21 @@ require a
200217[ bridging header] ( https://developer.apple.com/library/content/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html )
201218in order to use any React Native plugin in Swift.
202219
203- Add ` #import <react-native-branch /RNBranch.h> ` to your Bridging header if you
220+ Add ` #import <RNBranch /RNBranch.h> ` to your Bridging header if you
204221have one.
205222
206223If you have ` use_frameworks! ` in your Podfile, you may simply use a Swift
207224import.
208225
226+ Note that as of RN 0.60.3, it is not possible to ` use_frameworks! ` with
227+ native modules. See https://github.com/facebook/react-native/issues/25349 . A
228+ bridging header will be required for all RN dependencies.
229+ See [ webview_example_native_ios] for an example of a Swift app that
230+ uses a bridging header for React Native as well as an external Swift pod.
231+
209232In AppDelegate.swift:
210233``` Swift
211- import react_native_branch // omit if using a bridging header
234+ import RNBranch // omit if using a bridging header
212235
213236// Initialize the Branch Session at the top of existing application:didFinishLaunchingWithOptions:
214237func application (_ application : UIApplication, didFinishLaunchingWithOptions : [UIApplicationLaunchOptionsKey: Any ]? ) -> Bool {
@@ -229,7 +252,7 @@ func application(_ application: UIApplication, continue userActivity: NSUserActi
229252}
230253```
231254
232- These instructions are for Swift 3 and 4 .
255+ These instructions are for Swift 3-5 .
233256
234257### iOS Project Configuration
235258
@@ -246,56 +269,16 @@ ___
246269
247270### Android Setup
248271
249- #### Gradle dependency
250-
251- If you use ` react-native link ` , no further change is necessary to your ` app/build.gradle ` .
252-
253- In a native app, import the ` react-native-branch ` project like this:
254-
255- ``` gradle
256- implementation project(':react-native-branch')
257- ```
258-
259- If you're using an older version of Gradle, you may need ` compile ` rather than
260- ` implementation ` . If you are already using the native Branch SDK in your app,
261- it will now be imported from Maven via ` react-native-branch ` as a dependency.
262- Remove any reference to ` io.branch.sdk.android:library ` from your dependencies
263- to avoid conflicts.
264-
265- Also add the project to your ` settings.gradle ` :
266-
267- ``` gradle
268- include ':react-native-branch'
269- project(':react-native-branch').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-branch/android')
270- ```
271-
272- The location of your ` node_modules ` folder may vary.
273-
274272#### Application code
275273
276- Add RNBranchPackage to packages list in ` getPackages() ` MainApplication.java (` android/app/src/[...]/MainApplication.java ` ).
277- Note that this is automatically done if you used ` react-native link ` .
278-
279- Also add a call to ` RNBranchModule.getAutoinstance() ` in ` onCreate() ` in the same source file. This has to be
280- done even if you used ` react-native link ` .
274+ Add a call to ` RNBranchModule.getAutoinstance() ` in ` onCreate() ` in MainApplication.java.
281275``` java
282276// ...
283277
284278// import Branch and RNBranch
285- import io.branch.rnbranch.RNBranchPackage ;
286279import io.branch.rnbranch.RNBranchModule ;
287280
288281// ...
289-
290- // add RNBranchPackage to react-native package list
291- @Override
292- protected List<ReactPackage > getPackages() {
293- return Arrays . < ReactPackage > asList(
294- new MainReactPackage (),
295- new RNBranchPackage (), // <-- add this
296-
297- // ...
298-
299282 // add onCreate() override
300283 @Override
301284 public void onCreate() {
@@ -305,7 +288,6 @@ import io.branch.rnbranch.RNBranchModule;
305288```
306289
307290Override onStart and onNewIntent in MainActivity.java to handle Branch links (` android/app/src/[...]/MainActivity.java ` ).
308- This has to be done regardless whether you used `react- native link`.
309291``` java
310292import io.branch.rnbranch.* ; // <-- add this
311293import android.content.Intent ; // <-- and this
362344
363345## Example apps
364346
365- There are six example apps in this repo, including a [tutorial app]( . / examples / webview_tutorial) .
347+ There are six example apps in this repo, including a [ Tutorial app] .
366348See the [ examples] ( ./examples ) subdirectory for more details.
367349
350+ ## Tutorial app
351+
352+ The [ webview_tutorial] app is a functioning app using react-native 0.60.3 and
353+ react 16.8.6. The tutorial takes you step-by-step through adding this SDK to
354+ produce [ webview_example] with Branch integrated.
355+
368356___
369357
370358## SDK Documentation
0 commit comments