Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: wrap initialize sdk function #2

Merged
merged 3 commits into from
Mar 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,39 @@ The `AppDelegate.m` file can only have one method for `openUrl`. If you're also

## Usage

### SDK Initialization

To comply with Apple privacy requirements, for iOS the `autoInitEnabled` option is removed from [facebook-ios-sdk#v9.0.0](https://github.com/facebook/facebook-ios-sdk/blob/master/CHANGELOG.md#900).

Using this module, there are two options to comply with this requirement, one is platform-neutral and can be used from your javascript code whenever it makes sense for your app, and one is native.

#### Platform-neutral SDK initialization

If you do not need to handle a [GDPR-type opt-in flow](https://developers.facebook.com/docs/app-events/gdpr-compliance), on iOS you should include the following javascript code as early in startup as possible. For Android auto-init is the default still, so this is not strictly necessary for Android but will work.

If you need to handle a GDPR-type flow, make sure your SDK is configured natively to delay all logging activity according to [the GDPR instructions](https://developers.facebook.com/docs/app-events/gdpr-compliance), ask for user consent, and after obtaining consent include code similar to this:

```js
import { Settings } from 'react-native-fbsdk-next';

// Ask for consent first if necessary
// Possibly only do this for iOS if no need to handle a GDPR-type flow
Settings.initializeSDK();
```

#### iOS Native Initialization

If you would like to initialize the Facebook SDK even earlier in startup for iOS, you need to include this code in your AppDelegate.m file now that auto-initialization is removed.

```objective-c
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[FBSDKApplicationDelegate initializeSDK:launchOptions]; // <- add this

// your other stuff
}
```

### [Login](https://developers.facebook.com/docs/facebook-login)

#### Login Button + Access Token
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,13 @@ public void setDataProcessingOptions(@Nullable String[] options) {
public static void setDataProcessingOptionsExtra(@Nullable String[] options, int country, int state) {
FacebookSdk.setDataProcessingOptions(options, country, state);
}

/**
* Initialize the sdk
* [FB SDK Best Practices for GDPR Compliance](https://developers.facebook.com/docs/app-events/gdpr-compliance/)
*/
@ReactMethod
public static void initializeSDK() {
FacebookSdk.fullyInitialize();
}
}
11 changes: 10 additions & 1 deletion example/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,17 @@
* @format
*/

import {AppRegistry} from 'react-native';
import {AppRegistry, Platform} from 'react-native';
import App from './src/App';
import {name as appName} from './app.json';
import {Settings} from 'react-native-fbsdk';

/**
* The `autoInitEnabled` option is removed from facebook-ios-sdk, should initialize manually
* See https://github.com/facebook/facebook-ios-sdk/blob/master/CHANGELOG.md#removed
*/
if(Platform.OS === 'ios'){
Settings.initializeSDK();
}

AppRegistry.registerComponent(appName, () => App);
5 changes: 5 additions & 0 deletions ios/RCTFBSDK/core/RCTFBSDKSettings.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,9 @@ - (dispatch_queue_t)methodQueue
[FBSDKSettings setDataProcessingOptions:options country:country state:state];
}

RCT_EXPORT_METHOD(initializeSDK)
{
[FBSDKApplicationDelegate initializeSDK:nil];
}

@end
6 changes: 6 additions & 0 deletions src/FBSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,10 @@ module.exports = {
}
Settings.setDataProcessingOptions(options, country, state);
},
/**
* Initialize the sdk
*/
initializeSDK() {
Settings.initializeSDK();
},
};