Skip to content

Commit

Permalink
react-native-fbsdk-0.6.2
Browse files Browse the repository at this point in the history
  • Loading branch information
lepouya committed Oct 9, 2017
1 parent 390e4f4 commit 563f417
Show file tree
Hide file tree
Showing 43 changed files with 561 additions and 2,118 deletions.
21 changes: 21 additions & 0 deletions BUCK
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
include_defs("xplat//js/JS_DEFS")

js_library(
name = "react-native-fbsdk",
srcs = js_glob(
[
"**/*",
],
excludes = [
"bin/ios_setup.js",
],
),
visibility = ["PUBLIC"],
worker = "xplat//js:experimental-packager",
deps = [
"xplat//js:node_modules",
"xplat//js:react-native",
"xplat//js:react-native-RNTester",
"xplat//js:react-native-addons-node_modules",
],
)
4 changes: 2 additions & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ android {

defaultConfig {
minSdkVersion 16
targetSdkVersion 23
targetSdkVersion 25
}
buildTypes {
release {
Expand All @@ -19,5 +19,5 @@ android {
dependencies {
compile 'com.android.support:appcompat-v7:25.0.0'
compile 'com.facebook.react:react-native:+' // support react-native-v0.22-rc+
compile('com.facebook.android:facebook-android-sdk:4.22.1')
compile('com.facebook.android:facebook-android-sdk:4.+')
}
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,45 @@ public void logPushNotificationOpen(@Nullable ReadableMap payload) {
*
* @param userID A User ID
*/
@ReactMethod
public void setUserID(final String userID) {
@ReactMethod
public void setUserID(final String userID) {
mAppEventLogger.setUserID(userID);
}

/**
* Sets a user id to associate with all app events. This can be used to associate your own
* user id with the app events logged from this instance of an application.
*
* The user ID will be persisted between application instances.
*
* @param userID A User ID or null to reset
*/
@ReactMethod
public void setUserID(@Nullable String userID) {
mAppEventLogger.setUserID(userID);
}
}

/**
* Returns the set user id or null if not set
*
* @return The set User ID or null
*/
@ReactMethod(isBlockingSynchronousMethod = true)
@Nullable
public String getUserID() {
return mAppEventLogger.getUserID();
}

/**
* Sends a request to update the properties for the current user, set by
* setUserID. You must call setUserID before making this call.
*
* @param parameters Key-value pairs representing user properties and their values.
*/
@ReactMethod
public void updateUserProperties(ReadableMap parameters) {
mAppEventLogger.updateUserProperties(Arguments.toBundle(parameters), null);
}

/**
* Explicitly flush any stored events to the server. Implicit flushes may happen depending on
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

public class FBSDKPackage implements ReactPackage {

public static final String VERSION_TO_RELEASE = "ReactNative-v0.6.1";
public static final String VERSION_TO_RELEASE = "ReactNative-v0.6.2";

private CallbackManager mCallbackManager;
public FBSDKPackage(CallbackManager callbackManager) {
Expand Down
173 changes: 90 additions & 83 deletions bin/ios_setup.js
Original file line number Diff line number Diff line change
@@ -1,150 +1,157 @@
// Copyright 2004-present Facebook. All Rights Reserved.
/*
Copyright 2004-present Facebook. All Rights Reserved.
A node script to help set up FBSDK frameworks for use with https://github.com/facebook/react-native-fbsdk
after you have already run `rnpm install react-native-fbsdk`.
Note that you need to create a Facebook App in https://developers.facebook.com/
and get the Facebook APP ID and Facebook APP Name in order to set up the Info.plist.
Usage:
1. add to the package.json of your react-native project the following:
1. add to the 'script' section in package.json of your react-native project the following:
'"ios:setup": "node ./node_modules/react-native-fbsdk/bin/ios_setup.js"'.
2. do 'npm run ios:setup <AppID> <AppName>'.
*/

'use strict'
'use strict';

/* eslint-disable no-console */

const fs = require('fs')
const path = require('path')
const plist = require('plist')
const xcode = require('xcode')
const AdmZip = require('adm-zip')
const ProgressBar = require('progress')
const got = require('got')
const fall = require('fastfall')()
const pump = require('pump')
const AdmZip = require('adm-zip');
const ProgressBar = require('progress');

const progressBarPattern = ' downloading [:bar] :rate/bps :percent :etas'
const frameworkDir = 'ios/Frameworks/'
const zipFileName = 'fbsdk.zip'
const zipFilePath = path.join(frameworkDir, zipFileName)
const frameworkUrl = 'https://origincache.facebook.com/developers/resources/?id=facebook-ios-sdk-current.zip'
const fall = require('fastfall');
const fs = require('fs');
const got = require('got');
const path = require('path');
const plist = require('plist');
const pump = require('pump');
const xcode = require('xcode');

const progressBarPattern = ' downloading [:bar] :rate/bps :percent :etas';
const frameworkDir = 'ios/Frameworks/';
const zipFileName = 'fbsdk.zip';
const zipFilePath = path.join(frameworkDir, zipFileName);
const frameworkUrl = 'https://origincache.facebook.com/developers/resources/?id=facebook-ios-sdk-current.zip';

// Get Facebook App ID and App Name.
if (process.argv.length <= 3) {
console.log('Usage: ios_setup.js <APPID> <APPNAME>')
process.exit(-1)
console.log('Usage: ios_setup.js <APPID> <APPNAME>');
process.exit(-1);
}

const appId = process.argv[2]
const appName = process.argv[3]
const appId = process.argv[2];
const appName = process.argv[3];

function downloadFbSdk (next) {
try {
fs.accessSync(frameworkDir, fs.F_OK)
fs.accessSync(frameworkDir, fs.F_OK);
} catch (e) {
fs.mkdirSync(frameworkDir)
fs.mkdirSync(frameworkDir);
}

var bar = null
var bar = null;
var download = got.stream(frameworkUrl)
.on('data', chunk => {
bar.tick(chunk.length)
bar.tick(chunk.length);
})
.on('response', res => {
const len = parseInt(res.headers['content-length'], 10)
const len = parseInt(res.headers['content-length'], 10);
bar = new ProgressBar(progressBarPattern, {
complete: '=',
incomplete: ' ',
width: 20,
total: len
})
})
total: len,
});
});

var writeToFile = fs.createWriteStream(zipFilePath)
pump(download, writeToFile, next)
var writeToFile = fs.createWriteStream(zipFilePath);
pump(download, writeToFile, next);
}

function unzipFramework (next) {
console.log('Unzipping the framework')
const zip = new AdmZip(zipFilePath)
zip.extractAllTo(frameworkDir, true)
fs.unlinkSync(zipFilePath)
console.log('Framework Unzipped!')
next()
console.log('Unzipping the framework');
const zip = new AdmZip(zipFilePath);
zip.extractAllTo(frameworkDir, true);
fs.unlinkSync(zipFilePath);
console.log('Framework Unzipped!');
next();
}

function correctSearchPaths (next) {
const rctfbsdkProjectPath = './node_modules/react-native-fbsdk/ios/RCTFBSDK.xcodeproj/project.pbxproj'
const rctfbsdkProject = xcode.project(rctfbsdkProjectPath)
const rctfbsdkProjectPath = './node_modules/react-native-fbsdk/ios/RCTFBSDK.xcodeproj/project.pbxproj';
const rctfbsdkProject = xcode.project(rctfbsdkProjectPath);
rctfbsdkProject.parse(function (err) {
if (err) {
return next(err)
return next(err);
}
rctfbsdkProject.updateBuildProperty('FRAMEWORK_SEARCH_PATHS', '"$(PROJECT_DIR)/../../../ios/Frameworks"')
fs.writeFileSync(rctfbsdkProjectPath, rctfbsdkProject.writeSync())
console.log('Updated RCTFBSDK FRAMEWORK_SEARCH_PATHS')
next()
})
rctfbsdkProject.updateBuildProperty('FRAMEWORK_SEARCH_PATHS', '"$(PROJECT_DIR)/../../../ios/Frameworks"');
fs.writeFileSync(rctfbsdkProjectPath, rctfbsdkProject.writeSync());
console.log('Updated RCTFBSDK FRAMEWORK_SEARCH_PATHS');
next();
});
}

function updateFBSDKFrameworks (next) {
const files = fs.readdirSync('./ios/')
var myProjName = files.filter((f) => { return f.substr(-10) === '.xcodeproj' })[0]
const myProjPath = path.join('./ios/', myProjName, '/project.pbxproj')
myProjName = myProjName.replace('.xcodeproj', '')
console.log('Updating target:' + myProjName + ' at ' + myProjPath + ' ...')
const files = fs.readdirSync('./ios/');
var myProjName = files.filter((f) => { return f.substr(-10) === '.xcodeproj'; })[0];
const myProjPath = path.join('./ios/', myProjName, '/project.pbxproj');
myProjName = myProjName.replace('.xcodeproj', '');
console.log('Updating target:' + myProjName + ' at ' + myProjPath + ' ...');

const myProj = xcode.project(myProjPath)
const myProj = xcode.project(myProjPath);
myProj.parse(function (err) {
if (err) {
return next(err)
return next(err);
}
myProj.pbxCreateGroup('Frameworks', './ios/Frameworks')
myProj.pbxCreateGroup('Frameworks', './ios/Frameworks');

// NOTE: Assumes first target is the app.
const target = myProj.getFirstTarget().uuid
myProj.addFramework('./ios/Frameworks/FBSDKCoreKit.framework', { 'customFramework': true, 'target': target, 'link': true })
myProj.addFramework('./ios/Frameworks/FBSDKShareKit.framework', { 'customFramework': true, 'target': target, 'link': true })
myProj.addFramework('./ios/Frameworks/FBSDKLoginKit.framework', { 'customFramework': true, 'target': target, 'link': true })
const target = myProj.getFirstTarget().uuid;
myProj.addFramework('./ios/Frameworks/FBSDKCoreKit.framework', { 'customFramework': true, 'target': target, 'link': true });
myProj.addFramework('./ios/Frameworks/FBSDKShareKit.framework', { 'customFramework': true, 'target': target, 'link': true });
myProj.addFramework('./ios/Frameworks/FBSDKLoginKit.framework', { 'customFramework': true, 'target': target, 'link': true });

// WARNING: this will overwrite any existing search paths
myProj.updateBuildProperty('FRAMEWORK_SEARCH_PATHS', '"$(PROJECT_DIR)/Frameworks/"')
fs.writeFileSync(myProjPath, myProj.writeSync())
console.log('Finished updating ' + myProjPath)
myProj.updateBuildProperty('FRAMEWORK_SEARCH_PATHS', '"$(PROJECT_DIR)/Frameworks/"');
fs.writeFileSync(myProjPath, myProj.writeSync());
console.log('Finished updating ' + myProjPath);

next(null, files)
})
next(null, files);
});
}

function updatePlist (files, next) {
console.dir(files)
var plistDirPath = ''
console.dir(files);
var plistDirPath = '';
files.map(function (file) {
return path.join('./ios/', file)
return path.join('./ios/', file);
}).filter(function (file) {
return fs.statSync(file).isDirectory()
return fs.statSync(file).isDirectory();
}).forEach(function (file) {
if (fs.readdirSync(file).indexOf('Base.lproj') !== -1) {
plistDirPath = file
plistDirPath = file;
}
})
const plistFilePath = path.join(plistDirPath, '/Info.plist')
const plistFile = fs.readFileSync(plistFilePath, 'utf8')
const plistObject = plist.parse(plistFile)
plistObject.CFBundleURLTypes = [{CFBundleURLSchemes: ['fb' + appId]}]
plistObject.FacebookAppID = appId
plistObject.FacebookDisplayName = appName
plistObject.LSApplicationQueriesSchemes = ['fbapi', 'fb-messenger-api', 'fbauth2', 'fbshareextension']
plistObject.NSLocationWhenInUseUsageDescription = ''
fs.writeFileSync(plistFilePath, plist.build(plistObject))
console.log('Finished updating ' + plistFilePath)
next()
});
const plistFilePath = path.join(plistDirPath, '/Info.plist');
const plistFile = fs.readFileSync(plistFilePath, 'utf8');
const plistObject = plist.parse(plistFile);
plistObject.CFBundleURLTypes = [{CFBundleURLSchemes: ['fb' + appId]}];
plistObject.FacebookAppID = appId;
plistObject.FacebookDisplayName = appName;
plistObject.LSApplicationQueriesSchemes = ['fbapi', 'fb-messenger-api', 'fbauth2', 'fbshareextension'];
plistObject.NSLocationWhenInUseUsageDescription = '';
fs.writeFileSync(plistFilePath, plist.build(plistObject));
console.log('Finished updating ' + plistFilePath);
next();
}

function done (err) {
if (err) console.error(err)
else console.log('DONE!')
if (err) {
console.error(err);
} else {
console.log('DONE!');
}
}

fall([downloadFbSdk, unzipFramework, correctSearchPaths, updateFBSDKFrameworks, updatePlist], done)
fall([downloadFbSdk, unzipFramework, correctSearchPaths, updateFBSDKFrameworks, updatePlist], done);
Loading

0 comments on commit 563f417

Please sign in to comment.