Skip to content
This repository was archived by the owner on Jan 16, 2021. It is now read-only.

Commit 40d347a

Browse files
committed
Merge pull request #69 from ParsePlatform/nlutsenko.fbutils_v4
Add support for ParseFacebookUtilsV4 and FBSDKv4.
2 parents 834d102 + aa135ee commit 40d347a

File tree

10 files changed

+78
-40
lines changed

10 files changed

+78
-40
lines changed

ParseUI.podspec

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,5 @@ Pod::Spec.new do |s|
3333
'CoreGraphics',
3434
'QuartzCore'
3535

36-
s.dependency 'Parse', '~> 1.6'
37-
s.dependency 'ParseFacebookUtils', '~> 1.6'
36+
s.dependency 'Parse', '~> 1.7'
3837
end

ParseUI.xcodeproj/project.pbxproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,7 @@
811811
isa = PBXProject;
812812
attributes = {
813813
CLASSPREFIX = PF;
814-
LastUpgradeCheck = 0610;
814+
LastUpgradeCheck = 0620;
815815
ORGANIZATIONNAME = "Parse Inc.";
816816
TargetAttributes = {
817817
81472F661A1AB33800FD6EED = {
@@ -1219,7 +1219,7 @@
12191219
GCC_WARN_UNDECLARED_SELECTOR = YES;
12201220
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
12211221
INFOPLIST_FILE = ParseUIDemo/Other/Info.plist;
1222-
IPHONEOS_DEPLOYMENT_TARGET = 6.0;
1222+
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
12231223
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
12241224
PRODUCT_NAME = "$(TARGET_NAME)";
12251225
TARGETED_DEVICE_FAMILY = "1,2";
@@ -1251,7 +1251,7 @@
12511251
GCC_WARN_UNDECLARED_SELECTOR = YES;
12521252
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
12531253
INFOPLIST_FILE = ParseUIDemo/Other/Info.plist;
1254-
IPHONEOS_DEPLOYMENT_TARGET = 6.0;
1254+
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
12551255
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
12561256
PRODUCT_NAME = "$(TARGET_NAME)";
12571257
TARGETED_DEVICE_FAMILY = "1,2";

ParseUI.xcodeproj/xcshareddata/xcschemes/ParseUI.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0610"
3+
LastUpgradeVersion = "0620"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

ParseUI.xcodeproj/xcshareddata/xcschemes/ParseUIDemo-Swift.xcscheme

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0610"
3+
LastUpgradeVersion = "0620"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"
@@ -48,7 +48,8 @@
4848
ignoresPersistentStateOnLaunch = "NO"
4949
debugDocumentVersioning = "YES"
5050
allowLocationSimulation = "YES">
51-
<BuildableProductRunnable>
51+
<BuildableProductRunnable
52+
runnableDebuggingMode = "0">
5253
<BuildableReference
5354
BuildableIdentifier = "primary"
5455
BlueprintIdentifier = "8129E5DE1A9CB067006752BC"
@@ -66,7 +67,8 @@
6667
useCustomWorkingDirectory = "NO"
6768
buildConfiguration = "Release"
6869
debugDocumentVersioning = "YES">
69-
<BuildableProductRunnable>
70+
<BuildableProductRunnable
71+
runnableDebuggingMode = "0">
7072
<BuildableReference
7173
BuildableIdentifier = "primary"
7274
BlueprintIdentifier = "8129E5DE1A9CB067006752BC"

ParseUI.xcodeproj/xcshareddata/xcschemes/ParseUIDemo.xcscheme

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0610"
3+
LastUpgradeVersion = "0620"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"
@@ -48,7 +48,8 @@
4848
ignoresPersistentStateOnLaunch = "NO"
4949
debugDocumentVersioning = "YES"
5050
allowLocationSimulation = "YES">
51-
<BuildableProductRunnable>
51+
<BuildableProductRunnable
52+
runnableDebuggingMode = "0">
5253
<BuildableReference
5354
BuildableIdentifier = "primary"
5455
BlueprintIdentifier = "81472F661A1AB33800FD6EED"
@@ -66,7 +67,8 @@
6667
useCustomWorkingDirectory = "NO"
6768
buildConfiguration = "Release"
6869
debugDocumentVersioning = "YES">
69-
<BuildableProductRunnable>
70+
<BuildableProductRunnable
71+
runnableDebuggingMode = "0">
7072
<BuildableReference
7173
BuildableIdentifier = "primary"
7274
BlueprintIdentifier = "81472F661A1AB33800FD6EED"

ParseUI/Classes/LogInViewController/PFLogInViewController.m

Lines changed: 49 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,13 @@
3737
This protocol exists so that we can weakly refer to messages to pass to PFFacebookUtils without
3838
actually taking a dependency on the symbols.
3939
*/
40-
@protocol WeaklyReferencedFBUtils
40+
@protocol WeaklyReferencedFBUtils <NSObject>
4141

42-
+ (void)logInWithPermissions:(NSArray *)permissions block:(void(^)(PFUser *user, NSError *error))block;
42+
// FBSDKv3
43+
+ (void)logInWithPermissions:(NSArray *)permissions block:(PFUserResultBlock)block;
44+
// FBSDKv4
45+
+ (void)logInInBackgroundWithReadPermissions:(NSArray *)permissions block:(PFUserResultBlock)block;
46+
+ (void)logInInBackgroundWithPublishPermissions:(NSArray *)permissions block:(PFUserResultBlock)block;
4347

4448
@end
4549

@@ -279,6 +283,8 @@ - (void)_requestPasswordResetWithEmail:(NSString *)email {
279283
}];
280284
}
281285

286+
#pragma mark Log In With Facebook
287+
282288
- (void)_loginWithFacebook {
283289
if (self.loading) {
284290
return;
@@ -289,23 +295,55 @@ - (void)_loginWithFacebook {
289295
[(PFActionButton *)_logInView.facebookButton setLoading:YES];
290296
}
291297

292-
Class fbUtils = NSClassFromString(@"PFFacebookUtils");
293-
[fbUtils logInWithPermissions:_facebookPermissions block:^(PFUser *user, NSError *error) {
294-
self.loading = NO;
298+
__weak typeof(self) wself = self;
299+
PFUserResultBlock resultBlock = ^(PFUser *user, NSError *error) {
300+
__strong typeof(wself) sself = wself;
301+
sself.loading = NO;
295302
if ([_logInView.facebookButton isKindOfClass:[PFActionButton class]]) {
296303
[(PFActionButton *)_logInView.facebookButton setLoading:NO];
297304
}
298305

299306
if (user) {
300-
[self _loginDidSuceedWithUser:user];
307+
[sself _loginDidSuceedWithUser:user];
301308
} else if (error) {
302-
[self _loginDidFailWithError:error];
309+
[sself _loginDidFailWithError:error];
303310
} else {
304311
// User cancelled login.
305312
}
306-
}];
313+
};
314+
315+
Class fbUtils = NSClassFromString(@"PFFacebookUtils");
316+
if ([fbUtils respondsToSelector:@selector(logInWithPermissions:block:)]) {
317+
// Facebook SDK v3 Login
318+
[fbUtils logInWithPermissions:_facebookPermissions block:resultBlock];
319+
} else if ([fbUtils respondsToSelector:@selector(logInInBackgroundWithReadPermissions:block:)]) {
320+
// Facebook SDK v4 Login
321+
if ([self _permissionsContainsFacebookPublishPermission:_facebookPermissions]) {
322+
[fbUtils logInInBackgroundWithPublishPermissions:_facebookPermissions block:resultBlock];
323+
} else {
324+
[fbUtils logInInBackgroundWithReadPermissions:_facebookPermissions block:resultBlock];
325+
}
326+
} else {
327+
[NSException raise:NSInternalInconsistencyException
328+
format:@"Can't find PFFacebookUtils. Please link with ParseFacebookUtils or ParseFacebookUtilsV4 to enable login with Facebook."];
329+
}
330+
}
331+
332+
- (BOOL)_permissionsContainsFacebookPublishPermission:(NSArray *)permissions {
333+
for (NSString *permission in permissions) {
334+
if ([permission hasPrefix:@"publish"] ||
335+
[permission hasPrefix:@"manage"] ||
336+
[permission isEqualToString:@"ads_management"] ||
337+
[permission isEqualToString:@"create_event"] ||
338+
[permission isEqualToString:@"rsvp_event"]) {
339+
return YES;
340+
}
341+
}
342+
return NO;
307343
}
308344

345+
#pragma mark Log In With Twitter
346+
309347
- (void)_loginWithTwitter {
310348
if (self.loading) {
311349
return;
@@ -332,6 +370,8 @@ - (void)_loginWithTwitter {
332370
}];
333371
}
334372

373+
#pragma mark Log In
374+
335375
- (void)_loginAction {
336376
if (self.loading) {
337377
return;
@@ -522,7 +562,7 @@ - (void)_updateViewContentOffsetAnimated:(BOOL)animated {
522562
contentOffset = CGPointMake(0.0f, MIN(offsetForScrollingTextFieldToTop,
523563
offsetForScrollingLowestViewToBottom));
524564
}
525-
565+
526566
[_logInView setContentOffset:contentOffset animated:animated];
527567
}
528568

ParseUIDemo/Classes/AppDelegate.m

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
#import "AppDelegate.h"
2323

2424
#import <Parse/Parse.h>
25-
26-
#import <ParseFacebookUtils/PFFacebookUtils.h>
25+
#import <ParseFacebookUtilsV4/PFFacebookUtils.h>
26+
#import <FBSDKCoreKit/FBSDKApplicationDelegate.h>
2727

2828
#import "PFUIDemoViewController.h"
2929

@@ -35,7 +35,7 @@ @implementation AppDelegate
3535
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
3636
[Parse setApplicationId:@"UdNpOP2XFoEiXLZEBDl6xONmCMH8VjETmnEsl0xJ"
3737
clientKey:@"wNJFho0fQaQFQ2Fe1x9b67lVBakJiAtFj1Uz30A9"];
38-
[PFFacebookUtils initializeFacebook];
38+
[PFFacebookUtils initializeFacebookWithApplicationLaunchOptions:launchOptions];
3939
[PFTwitterUtils initializeWithConsumerKey:@"3Q9hMEKqqSg4ie2pibZ2sVJuv"
4040
consumerSecret:@"IEZ9wv2d1EpXNGFKGp7sAGdxRtyqtPwygyciFZwTHTGhPp4FMj"];
4141

@@ -54,13 +54,10 @@ - (BOOL)application:(UIApplication *)application
5454
openURL:(NSURL *)url
5555
sourceApplication:(NSString *)sourceApplication
5656
annotation:(id)annotation {
57-
return [FBAppCall handleOpenURL:url
58-
sourceApplication:sourceApplication
59-
withSession:[PFFacebookUtils session]];
60-
}
61-
62-
- (void)applicationDidBecomeActive:(UIApplication *)application {
63-
[FBAppCall handleDidBecomeActiveWithSession:[PFFacebookUtils session]];
57+
return [[FBSDKApplicationDelegate sharedInstance] application:application
58+
openURL:url
59+
sourceApplication:sourceApplication
60+
annotation:annotation];
6461
}
6562

6663
#pragma mark -

ParseUIDemo/Swift/AppDelegate.swift

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
3131

3232
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool {
3333
Parse.setApplicationId("UdNpOP2XFoEiXLZEBDl6xONmCMH8VjETmnEsl0xJ", clientKey: "wNJFho0fQaQFQ2Fe1x9b67lVBakJiAtFj1Uz30A9")
34-
PFFacebookUtils.initializeFacebook()
34+
PFFacebookUtils.initializeFacebookWithApplicationLaunchOptions(launchOptions);
3535
PFTwitterUtils.initializeWithConsumerKey("3Q9hMEKqqSg4ie2pibZ2sVJuv", consumerSecret: "IEZ9wv2d1EpXNGFKGp7sAGdxRtyqtPwygyciFZwTHTGhPp4FMj")
3636

3737
window = UIWindow(frame: UIScreen.mainScreen().bounds)
@@ -46,11 +46,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
4646
}
4747

4848
func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject?) -> Bool {
49-
return FBAppCall.handleOpenURL(url, sourceApplication: sourceApplication, withSession: PFFacebookUtils.session())
50-
}
51-
52-
func applicationDidBecomeActive(application: UIApplication) {
53-
FBAppCall.handleDidBecomeActiveWithSession(PFFacebookUtils.session())
49+
return FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)
5450
}
5551

5652
// MARK: Test Data

ParseUIDemo/Swift/ParseUIDemo-Bridging-Header.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#define ParseStarterProject_Bridging_Header_h
2424

2525
#import <Bolts/Bolts.h>
26-
#import <ParseFacebookUtils/PFFacebookUtils.h>
26+
#import <ParseFacebookUtilsV4/PFFacebookUtils.h>
27+
#import <FBSDKCoreKit/FBSDKCoreKit.h>
2728

2829
#endif

Podfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ source 'https://github.com/CocoaPods/Specs.git'
33
workspace 'ParseUI'
44
xcodeproj 'ParseUI.xcodeproj'
55
link_with 'ParseUIDemo'
6+
platform :ios, "7.0"
67

7-
pod 'Parse', '~> 1.6'
8-
pod 'ParseFacebookUtils', '~> 1.6'
8+
pod 'Parse', '~> 1.7'
9+
pod 'ParseFacebookUtilsV4', '~> 1.7'

0 commit comments

Comments
 (0)