Skip to content
This repository has been archived by the owner on Apr 2, 2021. It is now read-only.

Implement fetch deferred app link #813

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
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
* <p/>
* 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.
* <p/>
* 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.
* <p/>
* 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 com.facebook.applinks.AppLinkData;
import com.facebook.internal.Utility;
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.module.annotations.ReactModule;

import org.json.JSONObject;

/**
* FBAppLinkModule
*/
@ReactModule(name = FBAppLinkModule.NAME)
public class FBAppLinkModule extends ReactContextBaseJavaModule {
public static final String NAME = "FBAppLink";

private final ReactApplicationContext mReactContext;

public FBAppLinkModule(ReactApplicationContext reactContext) {
super(reactContext);
mReactContext = reactContext;
}

@Override
public String getName() {
return NAME;
}

/**
* The completion handler of fetchDeferredAppLinkData.
*
* @param promise If AppLinkData is found, resolve app link url, otherwise resolve null.
*/
private AppLinkData.CompletionHandler createCompletionHandler(final Promise promise) {
return new AppLinkData.CompletionHandler() {
@Override
public void onDeferredAppLinkDataFetched(AppLinkData appLinkData) {
if (appLinkData == null) {
promise.resolve(null);
} else {
promise.resolve(appLinkData.getTargetUri().toString());
}
}
};
}

/**
* Asynchronously fetches app link information that might have been stored for use after
* installation of the app.
*
* @param promise Used to pass app link to JS on fetch completed using completion handler.
*/
@ReactMethod
public void fetchDeferredAppLink(final Promise promise) {
try {
AppLinkData.fetchDeferredAppLinkData(mReactContext.getApplicationContext(),
createCompletionHandler(promise));
} catch (Exception e) {
promise.resolve(null);
Utility.logd(getName(), "Received error while fetching deferred app link", e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public List<NativeModule> createNativeModules(
return Arrays.<NativeModule>asList(
new FBAccessTokenModule(reactContext),
new FBAppEventsLoggerModule(reactContext),
new FBAppLinkModule(reactContext),
new FBGameRequestDialogModule(reactContext, mActivityEventListener),
new FBGraphRequestModule(reactContext),
new FBLoginManagerModule(reactContext, mActivityEventListener),
Expand Down
6 changes: 6 additions & 0 deletions ios/RCTFBSDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
93E005141CE3D2D3000598E3 /* RCTFBSDKShareButtonManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 93E005061CE3D2D3000598E3 /* RCTFBSDKShareButtonManager.m */; };
93E005151CE3D2D3000598E3 /* RCTFBSDKShareDialog.m in Sources */ = {isa = PBXBuildFile; fileRef = 93E005081CE3D2D3000598E3 /* RCTFBSDKShareDialog.m */; };
93E005161CE3D2D3000598E3 /* RCTFBSDKShareHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 93E0050A1CE3D2D3000598E3 /* RCTFBSDKShareHelper.m */; };
F1191EC92560474100A8767F /* RCTFBSDKAppLink.m in Sources */ = {isa = PBXBuildFile; fileRef = F1191EC82560474100A8767F /* RCTFBSDKAppLink.m */; };
/* End PBXBuildFile section */

/* Begin PBXCopyFilesBuildPhase section */
Expand Down Expand Up @@ -77,6 +78,8 @@
93E005081CE3D2D3000598E3 /* RCTFBSDKShareDialog.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RCTFBSDKShareDialog.m; path = share/RCTFBSDKShareDialog.m; sourceTree = "<group>"; };
93E005091CE3D2D3000598E3 /* RCTFBSDKShareHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RCTFBSDKShareHelper.h; path = share/RCTFBSDKShareHelper.h; sourceTree = "<group>"; };
93E0050A1CE3D2D3000598E3 /* RCTFBSDKShareHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RCTFBSDKShareHelper.m; path = share/RCTFBSDKShareHelper.m; sourceTree = "<group>"; };
F1191EC82560474100A8767F /* RCTFBSDKAppLink.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RCTFBSDKAppLink.m; path = core/RCTFBSDKAppLink.m; sourceTree = "<group>"; };
F1191ECB25604E4B00A8767F /* RCTFBSDKAppLink.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RCTFBSDKAppLink.h; path = core/RCTFBSDKAppLink.h; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -143,6 +146,8 @@
93E004E01CE3D292000598E3 /* RCTFBSDKAppEvents.m */,
93E004E11CE3D292000598E3 /* RCTFBSDKGraphRequestManager.h */,
93E004E21CE3D292000598E3 /* RCTFBSDKGraphRequestManager.m */,
F1191ECB25604E4B00A8767F /* RCTFBSDKAppLink.h */,
F1191EC82560474100A8767F /* RCTFBSDKAppLink.m */,
);
name = core;
sourceTree = "<group>";
Expand Down Expand Up @@ -254,6 +259,7 @@
93E005141CE3D2D3000598E3 /* RCTFBSDKShareButtonManager.m in Sources */,
93E005131CE3D2D3000598E3 /* RCTFBSDKShareAPI.m in Sources */,
93E004F11CE3D2B4000598E3 /* RCTFBSDKLoginManager.m in Sources */,
F1191EC92560474100A8767F /* RCTFBSDKAppLink.m in Sources */,
93E005121CE3D2D3000598E3 /* RCTFBSDKSendButtonManager.m in Sources */,
93B905C21D2D987F0013CC92 /* RCTFBSDKGraphRequestConnectionContainer.m in Sources */,
);
Expand Down
24 changes: 24 additions & 0 deletions ios/RCTFBSDK/core/RCTFBSDKAppLink.h
Original file line number Diff line number Diff line change
@@ -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 <React/RCTBridgeModule.h>

#import <FBSDKCoreKit/FBSDKCoreKit.h>

@interface RCTFBSDKAppLink : NSObject <RCTBridgeModule>
@end
52 changes: 52 additions & 0 deletions ios/RCTFBSDK/core/RCTFBSDKAppLink.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// 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 "RCTFBSDKAppLink.h"

#import <React/RCTUtils.h>

@implementation RCTFBSDKAppLink

RCT_EXPORT_MODULE(FBAppLink);

- (dispatch_queue_t)methodQueue
{
return dispatch_get_main_queue();
}

#pragma mark - React Native Methods

RCT_REMAP_METHOD(fetchDeferredAppLink,
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)
{
[FBSDKAppLinkUtility fetchDeferredAppLink:^(NSURL *url, NSError *error) {
if (error) {
NSLog(@"Received error while fetching deferred app link %@", error);
}

if (url) {
NSString* appLink = [NSString stringWithFormat:@"%@", url];
resolve(appLink);
}else{
resolve(nil);
}
}];
}

@end
31 changes: 31 additions & 0 deletions src/FBAppLink.js
Original file line number Diff line number Diff line change
@@ -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 AppLink = require('react-native').NativeModules.FBAppLink;

module.exports = {
fetchDeferredAppLink(): Promise<string | null> {
return AppLink.fetchDeferredAppLink();
},
};
3 changes: 3 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ module.exports = {
get AppEventsLogger() {
return require('./FBAppEventsLogger');
},
get AppLink() {
return require('./FBAppLink');
},
get GameRequestDialog() {
return require('./FBGameRequestDialog');
},
Expand Down