From 708c96569590580034ce327e713a985b40e8e31e Mon Sep 17 00:00:00 2001 From: Jimin Cutrell Date: Thu, 14 May 2020 17:43:36 -0700 Subject: [PATCH 1/3] Implement deferred deep linking modules --- .../androidsdk/FBAppLinkDataModule.java | 75 +++++++++++++++++++ .../reactnative/androidsdk/FBSDKPackage.java | 3 +- ios/RCTFBSDK.xcodeproj/project.pbxproj | 6 ++ ios/RCTFBSDK/RCTFBSDKAppLinkManager.h | 24 ++++++ ios/RCTFBSDK/core/RCTFBSDKAppLinkManager.m | 57 ++++++++++++++ js/FBAppLinkData.js | 31 ++++++++ js/index.js | 3 + 7 files changed, 198 insertions(+), 1 deletion(-) create mode 100644 android/src/main/java/com/facebook/reactnative/androidsdk/FBAppLinkDataModule.java create mode 100644 ios/RCTFBSDK/RCTFBSDKAppLinkManager.h create mode 100644 ios/RCTFBSDK/core/RCTFBSDKAppLinkManager.m create mode 100644 js/FBAppLinkData.js diff --git a/android/src/main/java/com/facebook/reactnative/androidsdk/FBAppLinkDataModule.java b/android/src/main/java/com/facebook/reactnative/androidsdk/FBAppLinkDataModule.java new file mode 100644 index 00000000..0b8484fd --- /dev/null +++ b/android/src/main/java/com/facebook/reactnative/androidsdk/FBAppLinkDataModule.java @@ -0,0 +1,75 @@ +/** + * Copyright (c) 2014-present, Facebook, Inc. All rights reserved. + * + * You are hereby granted a non-exclusive, worldwide, royalty-free license to use, + * copy, modify, and distribute this software in source code or binary form for use + * in connection with the web services and APIs provided by Facebook. + * + * As with any software that integrates with the Facebook platform, your use of + * this software is subject to the Facebook Developer Principles and Policies + * [http://developers.facebook.com/policy/]. This copyright notice shall be + * included in all copies or substantial portions of the software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package com.facebook.reactnative.androidsdk; + +import android.support.annotation.Nullable; + +import com.facebook.applinks.AppLinkData; +import com.facebook.applinks.FacebookAppLinkResolver; +import com.facebook.react.bridge.Arguments; +import com.facebook.react.bridge.Promise; +import com.facebook.react.bridge.ReactApplicationContext; +import com.facebook.react.bridge.ReactContextBaseJavaModule; +import com.facebook.react.bridge.ReactMethod; +import com.facebook.react.bridge.ReadableMap; + +public class FBAppLinkDataModule extends ReactContextBaseJavaModule { + + private class CompletionHandler implements AppLinkData.CompletionHandler { + + private Promise mPromise; + + public CompletionHandler(final Promise promise) { + mPromise = promise; + } + + /** + * This method is called when deferred app link data has been fetched. If no app link data + * was found, this method is called with null + * + * @param appLinkData The app link data that was fetched. Null if none was found. + */ + @Override + void onDeferredAppLinkDataFetched(AppLinkData appLinkData) { + if (appLinkData == null) { + mPromise.resolve(null); + } else { + mPromise.resolve(appLinkData.getTargetUri().toString()); + } + } + } + + private ReactApplicationContext mReactContext; + + public FBAppLinkDataModule(ReactApplicationContext reactContext) { + super(reactContext); + mReactContext = reactContext; + } + + public String getName() { + return "FBAppLinkData"; + } + + @ReactMethod + public void fetchDeferredAppLinkData(final Promise promise) { + AppLinkData.fetchDeferredAppLinkData(mReactContext, new CompletionHandler(promise)); + } +} diff --git a/android/src/main/java/com/facebook/reactnative/androidsdk/FBSDKPackage.java b/android/src/main/java/com/facebook/reactnative/androidsdk/FBSDKPackage.java index 9b49e560..f04896a3 100644 --- a/android/src/main/java/com/facebook/reactnative/androidsdk/FBSDKPackage.java +++ b/android/src/main/java/com/facebook/reactnative/androidsdk/FBSDKPackage.java @@ -54,7 +54,8 @@ public List createNativeModules( new FBLoginManagerModule(reactContext, mCallbackManager), new FBMessageDialogModule(reactContext, mCallbackManager), new FBShareAPIModule(reactContext), - new FBShareDialogModule(reactContext, mCallbackManager) + new FBShareDialogModule(reactContext, mCallbackManager), + new FBAppLinkDataModule(reactContext) ); } diff --git a/ios/RCTFBSDK.xcodeproj/project.pbxproj b/ios/RCTFBSDK.xcodeproj/project.pbxproj index 267453ac..efa24621 100644 --- a/ios/RCTFBSDK.xcodeproj/project.pbxproj +++ b/ios/RCTFBSDK.xcodeproj/project.pbxproj @@ -29,6 +29,7 @@ 93E005151CE3D2D3000598E3 /* RCTFBSDKShareDialog.m in Sources */ = {isa = PBXBuildFile; fileRef = 93E005081CE3D2D3000598E3 /* RCTFBSDKShareDialog.m */; }; 93E005161CE3D2D3000598E3 /* RCTFBSDKShareHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 93E0050A1CE3D2D3000598E3 /* RCTFBSDKShareHelper.m */; }; 93E005311CE3D63D000598E3 /* RCTFBSDKInitializer.m in Sources */ = {isa = PBXBuildFile; fileRef = 93E005301CE3D63D000598E3 /* RCTFBSDKInitializer.m */; }; + EC3D0E9C246CF88200E35EB7 /* RCTFBSDKAppLinkManager.m in Sources */ = {isa = PBXBuildFile; fileRef = EC3D0E9B246CF88200E35EB7 /* RCTFBSDKAppLinkManager.m */; }; /* End PBXBuildFile section */ /* Begin PBXCopyFilesBuildPhase section */ @@ -85,6 +86,8 @@ 93E005091CE3D2D3000598E3 /* RCTFBSDKShareHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RCTFBSDKShareHelper.h; path = share/RCTFBSDKShareHelper.h; sourceTree = ""; }; 93E0050A1CE3D2D3000598E3 /* RCTFBSDKShareHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RCTFBSDKShareHelper.m; path = share/RCTFBSDKShareHelper.m; sourceTree = ""; }; 93E005301CE3D63D000598E3 /* RCTFBSDKInitializer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RCTFBSDKInitializer.m; path = core/RCTFBSDKInitializer.m; sourceTree = ""; }; + EC3D0E9A246CF7F500E35EB7 /* RCTFBSDKAppLinkManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RCTFBSDKAppLinkManager.h; sourceTree = ""; }; + EC3D0E9B246CF88200E35EB7 /* RCTFBSDKAppLinkManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = RCTFBSDKAppLinkManager.m; path = core/RCTFBSDKAppLinkManager.m; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -142,6 +145,8 @@ isa = PBXGroup; children = ( 93B905C01D2D987F0013CC92 /* RCTFBSDKGraphRequestConnectionContainer.h */, + EC3D0E9A246CF7F500E35EB7 /* RCTFBSDKAppLinkManager.h */, + EC3D0E9B246CF88200E35EB7 /* RCTFBSDKAppLinkManager.m */, 93B905C11D2D987F0013CC92 /* RCTFBSDKGraphRequestConnectionContainer.m */, 93E005301CE3D63D000598E3 /* RCTFBSDKInitializer.m */, 93E004DB1CE3D292000598E3 /* RCTConvert+FBSDKAccessToken.h */, @@ -252,6 +257,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + EC3D0E9C246CF88200E35EB7 /* RCTFBSDKAppLinkManager.m in Sources */, 93E005151CE3D2D3000598E3 /* RCTFBSDKShareDialog.m in Sources */, 93E004E51CE3D292000598E3 /* RCTFBSDKAppEvents.m in Sources */, 93E004E61CE3D292000598E3 /* RCTFBSDKGraphRequestManager.m in Sources */, diff --git a/ios/RCTFBSDK/RCTFBSDKAppLinkManager.h b/ios/RCTFBSDK/RCTFBSDKAppLinkManager.h new file mode 100644 index 00000000..04d7c753 --- /dev/null +++ b/ios/RCTFBSDK/RCTFBSDKAppLinkManager.h @@ -0,0 +1,24 @@ +// Copyright (c) 2015-present, Facebook, Inc. All rights reserved. +// +// You are hereby granted a non-exclusive, worldwide, royalty-free license to use, +// copy, modify, and distribute this software in source code or binary form for use +// in connection with the web services and APIs provided by Facebook. +// +// As with any software that integrates with the Facebook platform, your use of +// this software is subject to the Facebook Developer Principles and Policies +// [http://developers.facebook.com/policy/]. This copyright notice shall be +// included in all copies or substantial portions of the software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +#import + +#import + +@interface RCTFBSDKAppLinkManager : NSObject +@end diff --git a/ios/RCTFBSDK/core/RCTFBSDKAppLinkManager.m b/ios/RCTFBSDK/core/RCTFBSDKAppLinkManager.m new file mode 100644 index 00000000..3283c0c0 --- /dev/null +++ b/ios/RCTFBSDK/core/RCTFBSDKAppLinkManager.m @@ -0,0 +1,57 @@ +// Copyright (c) 2015-present, Facebook, Inc. All rights reserved. +// +// You are hereby granted a non-exclusive, worldwide, royalty-free license to use, +// copy, modify, and distribute this software in source code or binary form for use +// in connection with the web services and APIs provided by Facebook. +// +// As with any software that integrates with the Facebook platform, your use of +// this software is subject to the Facebook Developer Principles and Policies +// [http://developers.facebook.com/policy/]. This copyright notice shall be +// included in all copies or substantial portions of the software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + +#import + +#import "RCTFBSDKAppLinkManager.h" +#import + +#import "RCTFBSDKAccessToken.h" + +#import + +#import "RCTConvert+FBSDKAccessToken.h" + +@implementation RCTFBSDKAppLinkManager + +RCT_EXPORT_MODULE(FBAppLinkData); + +- (dispatch_queue_t)methodQueue +{ + return dispatch_get_main_queue(); +} + +#pragma mark - React Native Methods + +RCT_EXPORT_METHOD(fetchDeferredAppLinkData:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) +{ + FBSDKDeferredAppLinkHandler handler = ^(NSURL *url, NSError *error) { + if (error) { + //reject(@"FacebookSDK", error.localizedDescription, error); + resolve("Test"); + } else { + NSString *urlString = [[url baseURL] absoluteString]; + resolve(urlString); + } + }; + + [FBSDKAppLinkUtility fetchDeferredAppLink:handler] +} + +@end diff --git a/js/FBAppLinkData.js b/js/FBAppLinkData.js new file mode 100644 index 00000000..6dfb1aa3 --- /dev/null +++ b/js/FBAppLinkData.js @@ -0,0 +1,31 @@ +/** + * Copyright (c) 2014-present, Facebook, Inc. All rights reserved. + * + * You are hereby granted a non-exclusive, worldwide, royalty-free license to use, + * copy, modify, and distribute this software in source code or binary form for use + * in connection with the web services and APIs provided by Facebook. + * + * As with any software that integrates with the Facebook platform, your use of + * this software is subject to the Facebook Developer Principles and Policies + * [http://developers.facebook.com/policy/]. This copyright notice shall be + * included in all copies or substantial portions of the software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * @flow + * @format + */ +'use strict'; + +const AppLinkData = require('react-native').NativeModules.FBAppLinkData; + +module.exports = { + async fetchDeferredAppLinkData(): Promise { + return await AppLinkData.fetchDeferredAppLinkData(); + }, +}; diff --git a/js/index.js b/js/index.js index f6145b65..25e81857 100644 --- a/js/index.js +++ b/js/index.js @@ -45,6 +45,9 @@ module.exports = { get AppInviteDialog() { return require('./FBAppInviteDialog'); }, + get AppLinkData() { + return require('./FBAppLinkData'); + }, get GameRequestDialog() { return require('./FBGameRequestDialog'); }, From 5151c2a735a923e5a33716e95fe4df8e95031c3e Mon Sep 17 00:00:00 2001 From: Jimin Cutrell Date: Thu, 14 May 2020 17:49:39 -0700 Subject: [PATCH 2/3] Remove test code --- ios/RCTFBSDK/core/RCTFBSDKAppLinkManager.m | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ios/RCTFBSDK/core/RCTFBSDKAppLinkManager.m b/ios/RCTFBSDK/core/RCTFBSDKAppLinkManager.m index 3283c0c0..b8b6e409 100644 --- a/ios/RCTFBSDK/core/RCTFBSDKAppLinkManager.m +++ b/ios/RCTFBSDK/core/RCTFBSDKAppLinkManager.m @@ -43,10 +43,9 @@ - (dispatch_queue_t)methodQueue { FBSDKDeferredAppLinkHandler handler = ^(NSURL *url, NSError *error) { if (error) { - //reject(@"FacebookSDK", error.localizedDescription, error); - resolve("Test"); + resolve(nil); } else { - NSString *urlString = [[url baseURL] absoluteString]; + NSString *urlString = [url absoluteString]; resolve(urlString); } }; From 9d0f25d18e27c1447730948f42e6b6a05c0e0a1f Mon Sep 17 00:00:00 2001 From: Jimin Cutrell Date: Thu, 14 May 2020 17:49:45 -0700 Subject: [PATCH 3/3] Add missing semicolon --- ios/RCTFBSDK/core/RCTFBSDKAppLinkManager.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ios/RCTFBSDK/core/RCTFBSDKAppLinkManager.m b/ios/RCTFBSDK/core/RCTFBSDKAppLinkManager.m index b8b6e409..4608e62d 100644 --- a/ios/RCTFBSDK/core/RCTFBSDKAppLinkManager.m +++ b/ios/RCTFBSDK/core/RCTFBSDKAppLinkManager.m @@ -50,7 +50,7 @@ - (dispatch_queue_t)methodQueue } }; - [FBSDKAppLinkUtility fetchDeferredAppLink:handler] + [FBSDKAppLinkUtility fetchDeferredAppLink:handler]; } @end