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 2 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
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,34 @@ The `AppDelegate.m` file can only have one method for `openUrl`. If you're also

## Usage

### SDK Initialization

The `autoInitEnabled` option is removed from [facebook-ios-sdk#v9.0.0](https://github.com/facebook/facebook-ios-sdk/blob/master/CHANGELOG.md#900).

On iOS, developers are required to initialize the sdk after app launched, implement the code below in your `AppDelegate.m`:

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

// your other stuff
}
```

Or call `Settings.initializeSDK` in anywhere else if you want the sdk to be initialized in react-native

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

if(Platform.OS === 'ios'){
Settings.initializeSDK();
}
```

> NOTE: `Settings.initializeSDK` is also functional for Android, if you want to comply with [GDPR](https://developers.facebook.com/docs/app-events/gdpr-compliance), `Settings.initializeSDK` can be called after an end user provides consent.

rnike marked this conversation as resolved.
Show resolved Hide resolved
### [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();
},
};