Skip to content

Commit

Permalink
Merge pull request #12 from appcelerator-modules/cheekiatng-updateFBSDK
Browse files Browse the repository at this point in the history
[TIMOB-18712] Upgrade iOS Facebook SDK, improve requestDialog
  • Loading branch information
cheekiatng committed Apr 21, 2015
2 parents 188538e + 229d4e7 commit 4e8b5f7
Show file tree
Hide file tree
Showing 23 changed files with 385 additions and 30 deletions.
20 changes: 16 additions & 4 deletions android/src/facebook/TiFacebookModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -687,12 +687,18 @@ public void onComplete(Bundle values,
data.put(PROPERTY_SUCCESS, true);
data.put(PROPERTY_CANCELLED, false);
data.put(PROPERTY_RESULT, requestId);
fireEvent(EVENT_REQUEST_DIALOG_COMPLETE, data);
} else {
data.put(PROPERTY_SUCCESS, false);
data.put(PROPERTY_CANCELLED, true);
fireEvent(EVENT_REQUEST_DIALOG_COMPLETE, data);
}
KrollDict valuesDict = new KrollDict();
for (String key : values.keySet()) {
String tempKey = key;
tempKey = tempKey.replace("[", "").replace("]", "");
valuesDict.put(tempKey, values.get(key).toString());
}
data.put(PROPERTY_DATA, valuesDict);
fireEvent(EVENT_REQUEST_DIALOG_COMPLETE, data);
}
}
})
Expand Down Expand Up @@ -729,12 +735,18 @@ public void onComplete(Bundle values,
data.put(PROPERTY_SUCCESS, true);
data.put(PROPERTY_CANCELLED, false);
data.put(PROPERTY_RESULT, requestId);
fireEvent(EVENT_REQUEST_DIALOG_COMPLETE, data);
} else {
data.put(PROPERTY_SUCCESS, false);
data.put(PROPERTY_CANCELLED, true);
fireEvent(EVENT_REQUEST_DIALOG_COMPLETE, data);
}
KrollDict valuesDict = new KrollDict();
for (String key : values.keySet()) {
String tempKey = key;
tempKey = tempKey.replace("[", "").replace("]", "");
valuesDict.put(tempKey, values.get(key).toString());
}
data.put(PROPERTY_DATA, valuesDict);
fireEvent(EVENT_REQUEST_DIALOG_COMPLETE, data);
}
}
})
Expand Down
12 changes: 9 additions & 3 deletions apidoc/Facebook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ description: |
fb.addEventListener('requestDialogCompleted', function (e) {
if (e.success) {
Ti.API.info('Share request succeeded.');
Ti.API.info('request succeeded.');
} else {
Ti.API.warn('Failed to share.');
}
Expand Down Expand Up @@ -546,7 +546,8 @@ methods:
summary: |
Opens an App Request dialog.
description: |
A `requestDialogCompleted` event is generated to indicate if the request attempt was successful or unsuccessful.
A `requestDialogCompleted` event is generated to indicate if the request attempt was successful or unsuccessful,
and the resultURL.
parameters:
- name: params
summary: |
Expand Down Expand Up @@ -754,7 +755,12 @@ events:
Error message, if any returned.
Will be undefined if `success` is `true`.
type: String
since: 4.0.0

- name: data
summary: |
data returned by Facebook. See Facebook reference for details.
type: Dictionary
since: 4.0.2

- name: shareCompleted
summary: Fired when the Share dialog or Web Share dialog is closed.
Expand Down
4 changes: 4 additions & 0 deletions documentation/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log
<pre>
v.4.0.2 Updated Facebook SDK from 3.21.1 to 3.23.1
Exposed data returned on presentSendRequestDialog
Bumped iOS module version to be same as android

v4.0.0 Combined and updated the Facebook module from https://github.com/mokesmokes/titanium-android-facebook/ and https://github.com/mokesmokes/titanium-ios-facebook

v3.0.3 Adding publishInstall method. [TIMODOPEN-246]
Expand Down
2 changes: 1 addition & 1 deletion example/facebook_publish_stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ exports.window = function(value){

fb.addEventListener('requestDialogCompleted', function(e) {
if (e.success) {
alert('Request dialog completed');
alert('Request dialog completed. Returned data is ' + e.data);
}
else if (e.cancelled) {
alert('Request dialog cancelled');
Expand Down
9 changes: 6 additions & 3 deletions ios/Classes/FacebookModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,7 @@ -(void)presentSendRequestDialog:(id)args
BOOL cancelled = NO;
BOOL success = NO;
NSString *errorDescription = @"";
NSDictionary *urlParams;
if (error) {
errorDescription = [FBErrorUtility userMessageForError:error];
} else {
Expand All @@ -544,7 +545,7 @@ -(void)presentSendRequestDialog:(id)args
success = NO;
} else {
// Handle the publish feed callback
NSDictionary *urlParams = [self parseURLParams:[resultURL query]];
urlParams = [self parseURLParams:[resultURL query]];
if (![urlParams valueForKey:@"request"]) {
// User cancelled.
cancelled = YES;
Expand All @@ -558,7 +559,8 @@ -(void)presentSendRequestDialog:(id)args
NSMutableDictionary *event = [NSMutableDictionary dictionaryWithObjectsAndKeys:
NUMBOOL(cancelled),@"cancelled",
NUMBOOL(success),@"success",
errorDescription,@"error",nil];
errorDescription,@"error",
urlParams,@"data",nil];
[self fireEvent:@"requestDialogCompleted" withObject:event];
}];
}, NO);
Expand Down Expand Up @@ -859,10 +861,11 @@ -(void)removeListener:(id<TiFacebookStateListener>)listener
- (NSDictionary*)parseURLParams:(NSString *)query {
NSArray *pairs = [query componentsSeparatedByString:@"&"];
NSMutableDictionary *params = [[[NSMutableDictionary alloc] init] autorelease];
NSCharacterSet *charSet = [NSCharacterSet characterSetWithCharactersInString:@"[]"];
for (NSString *pair in pairs) {
NSArray *kv = [pair componentsSeparatedByString:@"="];
NSString *val = [kv[1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
params[kv[0]] = val;
params[[[[kv[0] stringByRemovingPercentEncoding] componentsSeparatedByCharactersInSet:charSet] componentsJoinedByString:@""]] = val;
}
return params;
}
Expand Down
8 changes: 4 additions & 4 deletions ios/FacebookIOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

/* Begin PBXBuildFile section */
AACBBE4A0F95108600F1A2B1 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AACBBE490F95108600F1A2B1 /* Foundation.framework */; };
BB4741E51AB931D600A6B233 /* FacebookSDK.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BB4741E41AB931D600A6B233 /* FacebookSDK.framework */; };
BBA44FD71A93096C00D4C043 /* Facebook_Prefix.pch in Headers */ = {isa = PBXBuildFile; fileRef = BBA44FD61A93096C00D4C043 /* Facebook_Prefix.pch */; };
BBA44FE41A93097B00D4C043 /* FacebookLoginButtonProxy.m in Sources */ = {isa = PBXBuildFile; fileRef = BBA44FD81A93097B00D4C043 /* FacebookLoginButtonProxy.m */; };
BBA44FE51A93097B00D4C043 /* FacebookLoginButtonProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = BBA44FD91A93097B00D4C043 /* FacebookLoginButtonProxy.h */; };
Expand All @@ -36,7 +37,6 @@
BBA44FED1A93097B00D4C043 /* FacebookLikeButtonProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = BBA44FE11A93097B00D4C043 /* FacebookLikeButtonProxy.h */; };
BBA44FEE1A93097B00D4C043 /* FacebookLikeButton.h in Headers */ = {isa = PBXBuildFile; fileRef = BBA44FE21A93097B00D4C043 /* FacebookLikeButton.h */; };
BBA44FEF1A93097B00D4C043 /* FacebookLikeButton.m in Sources */ = {isa = PBXBuildFile; fileRef = BBA44FE31A93097B00D4C043 /* FacebookLikeButton.m */; };
EA7E24F619EC4A3A001B4B0C /* FacebookSDK.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EA7E24F519EC4A3A001B4B0C /* FacebookSDK.framework */; };
EAC238AA19F1280B00E8103C /* Social.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EAC238A919F1280B00E8103C /* Social.framework */; };
/* End PBXBuildFile section */

Expand All @@ -53,6 +53,7 @@
/* Begin PBXFileReference section */
24DD6D1B1134B66800162E58 /* titanium.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = titanium.xcconfig; sourceTree = "<group>"; };
AACBBE490F95108600F1A2B1 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
BB4741E41AB931D600A6B233 /* FacebookSDK.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = FacebookSDK.framework; path = platform/FacebookSDK.framework; sourceTree = "<group>"; };
BBA44FD61A93096C00D4C043 /* Facebook_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Facebook_Prefix.pch; sourceTree = "<group>"; };
BBA44FD81A93097B00D4C043 /* FacebookLoginButtonProxy.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = FacebookLoginButtonProxy.m; path = Classes/FacebookLoginButtonProxy.m; sourceTree = "<group>"; };
BBA44FD91A93097B00D4C043 /* FacebookLoginButtonProxy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = FacebookLoginButtonProxy.h; path = Classes/FacebookLoginButtonProxy.h; sourceTree = "<group>"; };
Expand All @@ -67,7 +68,6 @@
BBA44FE21A93097B00D4C043 /* FacebookLikeButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = FacebookLikeButton.h; path = Classes/FacebookLikeButton.h; sourceTree = "<group>"; };
BBA44FE31A93097B00D4C043 /* FacebookLikeButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = FacebookLikeButton.m; path = Classes/FacebookLikeButton.m; sourceTree = "<group>"; };
D2AAC07E0554694100DB518D /* libFacebook.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libFacebook.a; sourceTree = BUILT_PRODUCTS_DIR; };
EA7E24F519EC4A3A001B4B0C /* FacebookSDK.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = FacebookSDK.framework; path = platform/FacebookSDK.framework; sourceTree = "<group>"; };
EAC238A919F1280B00E8103C /* Social.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Social.framework; path = System/Library/Frameworks/Social.framework; sourceTree = SDKROOT; };
/* End PBXFileReference section */

Expand All @@ -78,7 +78,7 @@
files = (
EAC238AA19F1280B00E8103C /* Social.framework in Frameworks */,
AACBBE4A0F95108600F1A2B1 /* Foundation.framework in Frameworks */,
EA7E24F619EC4A3A001B4B0C /* FacebookSDK.framework in Frameworks */,
BB4741E51AB931D600A6B233 /* FacebookSDK.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -107,8 +107,8 @@
0867D69AFE84028FC02AAC07 /* Frameworks */ = {
isa = PBXGroup;
children = (
BB4741E41AB931D600A6B233 /* FacebookSDK.framework */,
EAC238A919F1280B00E8103C /* Social.framework */,
EA7E24F519EC4A3A001B4B0C /* FacebookSDK.framework */,
AACBBE490F95108600F1A2B1 /* Foundation.framework */,
);
name = Frameworks;
Expand Down
2 changes: 1 addition & 1 deletion ios/manifest
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# this is your module manifest and used by Titanium
# during compilation, packaging, distribution, etc.
#
version: 4.0.0
version: 4.0.2
apiversion: 2
description: Allows facebook integration for Titanium apps
author: Mark Mokryn and Ng Chee Kiat
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ typedef NS_ENUM(NSInteger, FBErrorCode) {
Reserved for future use.
*/
FBErrorOperationDisallowedForRestrictedTreatment,

/*!
The server returned a response that the SDK could not decode.
*/
FBErrorUnexpectedResponse,
};

/*!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,24 @@ typedef NSUInteger FBRequestState __attribute__((deprecated));
*/
+ (FBRequest *)requestForUploadPhoto:(UIImage *)photo;

/*!
@method
@abstract
Creates a request representing a Graph API call to upload a video to the app's album using the active session.
@discussion
Simplifies preparing a request to post a video.
This method does not initialize an <FBRequestConnection> object. To initiate the API
call first instantiate an <FBRequestConnection> object, add the request to this object,
then call the `start` method on the connection instance.
@param filePath A `NSString` for the video file to upload.
*/
+ (FBRequest *)requestForUploadVideo:(NSString *)filePath;

/*!
@method
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
See FBError.h and FBErrorUtility.h for error category and user message details.
*/
typedef NS_ENUM(NSUInteger, FBRequestConnectionErrorBehavior) {
typedef NS_OPTIONS(NSUInteger, FBRequestConnectionErrorBehavior) {
/*! The default behavior of none */
FBRequestConnectionErrorBehaviorNone = 0,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,8 @@ FBSDK_EXTERN NSString *kThirdTestUserTag;
/*!
@class FBTestSession
@abstract
Implements an FBSession subclass that knows about test users for a particular
application. This should never be used from a real application, but may be useful
for writing unit tests, etc.
@abstract Deprecated in favor of `FBTestUserSession`
and `FBTestUsersManager`
@discussion
Facebook allows developers to create test accounts for testing their applications'
Expand All @@ -67,6 +65,7 @@ FBSDK_EXTERN NSString *kThirdTestUserTag;
seems to be in an invalid state, it can be deleted manually via the Web interface at
https://developers.facebook.com/apps/APP_ID/permissions?role=test+users.
*/
__attribute__ ((deprecated("use FBTestUsersManager and FBTestUserSession instead")))
@interface FBTestSession : FBSession

/// The app access token (composed of app ID and secret) to use for accessing test users.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright 2010-present Facebook.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#import "FBAccessTokenData.h"
#import "FBSession.h"

/*!
@class FBTestUserSession
@abstract a "headless" (no UI) `FBSession` subclass that requires a token and is used for testing.
@discussion This will generally be used with `FBTestUsersManager` to help exercise
integration tests with Facebook. Use the class method `sessionWithAccessTokenData:` to construct
instances.
Note the supplied token data is not read until the session instance is "opened" (i.e., it will
never be in a "TokenLoaded" state) and uses
`[FBSessionTokenCachingStrategy nullCacheInstance]`.
Furthermore, reauthorization calls will succeed as a no-op (no new permissions added). You may toggle
the `treatReauthorizeAsCancellation` property to get cancellation treatment.
*/
@interface FBTestUserSession : FBSession

/*!
@abstract returns an instance
@discussion This should be used in place of any init methods.
*/
+ (instancetype)sessionWithAccessTokenData:(FBAccessTokenData *)tokenData;

/*!
@abstract Flag to treat reauthorize calls as cancelled.
@discussion
Defaults to NO. If set to YES, reauthorize calls will receive a nil token
as if the user had cancelled the reauthorize.
*/
@property (nonatomic, assign) BOOL treatReauthorizeAsCancellation;

/*!
@abstract Flag to force extending a token expiration at the next opportunity.
*/
@property (nonatomic, assign) BOOL forceAccessTokenExtension;
@end

0 comments on commit 4e8b5f7

Please sign in to comment.