Skip to content

Commit b98b66e

Browse files
authored
Merge pull request #473 from BranchMetrics/4.0-docs
4.0 docs
2 parents a69c730 + c043f14 commit b98b66e

File tree

918 files changed

+13990
-8521
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

918 files changed

+13990
-8521
lines changed

README.md

Lines changed: 89 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ ___
1818

1919
2. 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

2627
3. Branch general methods
2728
+ [Register a subscriber](#register-a-subscriber)
@@ -54,70 +55,95 @@ ___
5455
6. 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

6172
1. `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.
6878
See #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
140166
In 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)
201218
in 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
204221
have one.
205222

206223
If you have `use_frameworks!` in your Podfile, you may simply use a Swift
207224
import.
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+
209232
In 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:
214237
func 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;
286279
import 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

307290
Override 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
310292
import io.branch.rnbranch.*; // <-- add this
311293
import android.content.Intent; // <-- and this
@@ -362,9 +344,15 @@ ___
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].
366348
See 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

docs/version-3.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# react-native-branch version 3.0
2+
3+
This version is maintained to support versions of react-native < 0.60. If you
4+
are using react-native >= 0.60, please update to version 4.0 of this SDK.
5+
6+
## Installation
7+
8+
1. `yarn add react-native-branch`
9+
2. (Optional) Add a branch.json file to the root of your app project. See https://rnbranch.app.link/branch-json.
10+
3. `react-native link react-native-branch`
11+
4. Install the native Branch SDK using [CocoaPods](./cocoapods.md) or [Carthage](./carthage.md).
12+
5. Follow the [setup instructions](../README.md#setup).
13+
14+
## iOS imports
15+
16+
Use the following to import the react-native-branch SDK depending on your
17+
configuration:
18+
19+
Objective-C (static library, including Swift bridging header):
20+
```Obj-C
21+
#import <react-native-branch/RNBranch.h>
22+
```
23+
24+
Objective-C (framework):
25+
```Obj-C
26+
@import react_native_branch;
27+
```
28+
29+
Swift (framework):
30+
```Swift
31+
import react_native_branch
32+
```
33+
34+
Version 4.0 provides one import for each language, independent of other
35+
configuration and settings.
36+
37+
38+
## Gradle dependency
39+
40+
If you use `react-native link`, no further change is necessary to your `app/build.gradle`.
41+
42+
In a native app, import the `react-native-branch` project like this:
43+
44+
```gradle
45+
implementation project(':react-native-branch')
46+
```
47+
48+
If you're using an older version of Gradle, you may need `compile` rather than
49+
`implementation`. If you are already using the native Branch SDK in your app,
50+
it will now be imported from Maven via `react-native-branch` as a dependency.
51+
Remove any reference to `io.branch.sdk.android:library` from your dependencies
52+
to avoid conflicts.
53+
54+
Also add the project to your `settings.gradle`:
55+
56+
```gradle
57+
include ':react-native-branch'
58+
project(':react-native-branch').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-branch/android')
59+
```
60+
61+
The location of your `node_modules` folder may vary.

0 commit comments

Comments
 (0)