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

Add support for tvOS platform. #23

Merged
merged 6 commits into from
Dec 10, 2015
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ Vendor/Parse.framework
Vendor/Bolts.framework
Vendor/FBSDKCoreKit.framework
Vendor/FBSDKLoginKit.framework

Vendor/tvOS/FBSDKCoreKit.framework
Vendor/tvOS/FBSDKTVOSKit.framework
2 changes: 1 addition & 1 deletion Configurations/ParseFacebookUtilsV4-iOS.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ MACH_O_TYPE = staticlib
DEFINES_MODULE = YES
CLANG_ENABLE_MODULES = YES

INFOPLIST_FILE = $(SRCROOT)/Resources/Info.plist
INFOPLIST_FILE = $(SRCROOT)/Resources/Info-iOS.plist

FRAMEWORK_SEARCH_PATHS = $(inherited) $(SRCROOT)/Vendor
LIBRARY_SEARCH_PATHS = $(inherited) $(BUILT_PRODUCTS_DIR)
Expand Down
21 changes: 21 additions & 0 deletions Configurations/ParseFacebookUtilsV4-tvOS.xcconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// Copyright (c) 2015-present, Parse, LLC.
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
// LICENSE file in the root directory of this source tree. An additional grant
// of patent rights can be found in the PATENTS file in the same directory.
//

#include "Shared/Platform/tvOS.xcconfig"
#include "Shared/Product/Framework.xcconfig"

PRODUCT_NAME = ParseFacebookUtilsV4

MACH_O_TYPE = staticlib
DEFINES_MODULE = YES
CLANG_ENABLE_MODULES = YES

INFOPLIST_FILE = $(SRCROOT)/Resources/Info-tvOS.plist

FRAMEWORK_SEARCH_PATHS = $(inherited) $(SRCROOT)/Vendor/tvOS
232 changes: 216 additions & 16 deletions ParseFacebookUtils.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0720"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "81FE7F731C17790400E6BD34"
BuildableName = "ParseFacebookUtilsV4.framework"
BlueprintName = "ParseFacebookUtilsV4-tvOS"
ReferencedContainer = "container:ParseFacebookUtils.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "81FE7F731C17790400E6BD34"
BuildableName = "ParseFacebookUtilsV4.framework"
BlueprintName = "ParseFacebookUtilsV4-tvOS"
ReferencedContainer = "container:ParseFacebookUtils.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "81FE7F731C17790400E6BD34"
BuildableName = "ParseFacebookUtilsV4.framework"
BlueprintName = "ParseFacebookUtilsV4-tvOS"
ReferencedContainer = "container:ParseFacebookUtils.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,17 @@

#import <Foundation/Foundation.h>

#import <FBSDKLoginKit/FBSDKLoginManager.h>
#import <Bolts/BFTask.h>

#import <Parse/PFConstants.h>
#import <Parse/PFUserAuthenticationDelegate.h>

@class BFTask PF_GENERIC(__covariant BFGenericType);

NS_ASSUME_NONNULL_BEGIN

extern NSString *const PFFacebookUserAuthenticationType;

@interface PFFacebookAuthenticationProvider : NSObject <PFUserAuthenticationDelegate>

@property (nonatomic, strong, readonly) FBSDKLoginManager *loginManager;

///--------------------------------------
/// @name Init
///--------------------------------------
Expand All @@ -40,8 +36,11 @@ extern NSString *const PFFacebookUserAuthenticationType;
/// @name Authenticate
///--------------------------------------

- (BFTask *)authenticateAsyncWithReadPermissions:(nullable NSArray PF_GENERIC(NSString *) *)readPermissions
publishPermissions:(nullable NSArray PF_GENERIC(NSString *) *)publishPermissions;
- (BFTask PF_GENERIC(NSDictionary<NSString *, NSString *>*)*)authenticateAsyncWithReadPermissions:(nullable NSArray PF_GENERIC(NSString *)*)readPermissions
publishPermissions:(nullable NSArray PF_GENERIC(NSString *)*)publishPermissions;
- (BFTask PF_GENERIC(NSDictionary<NSString *, NSString *>*)*)authenticateAsyncWithReadPermissions:(nullable NSArray PF_GENERIC(NSString *)*)readPermissions
publishPermissions:(nullable NSArray PF_GENERIC(NSString *)*)publishPermissions
fromViewComtroller:(UIViewController *)viewController;

@end

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/**
* Copyright (c) 2015-present, Parse, LLC.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/

#import "PFFacebookAuthenticationProvider.h"

#import <FBSDKCoreKit/FBSDKAccessToken.h>
#import <FBSDKCoreKit/FBSDKApplicationDelegate.h>

#import "PFFacebookPrivateUtilities.h"

NSString *const PFFacebookUserAuthenticationType = @"facebook";

@implementation PFFacebookAuthenticationProvider

///--------------------------------------
#pragma mark - Init
///--------------------------------------

- (instancetype)initWithApplication:(UIApplication *)application
launchOptions:(nullable NSDictionary *)launchOptions {
self = [super init];
if (!self) return nil;

[[FBSDKApplicationDelegate sharedInstance] application:[UIApplication sharedApplication]
didFinishLaunchingWithOptions:launchOptions];

return self;
}

+ (instancetype)providerWithApplication:(UIApplication *)application
launchOptions:(nullable NSDictionary *)launchOptions {
return [[self alloc] initWithApplication:application launchOptions:launchOptions];
}

///--------------------------------------
#pragma mark - Authenticate
///--------------------------------------

- (BFTask PF_GENERIC(NSDictionary<NSString *, NSString *>*)*)authenticateAsyncWithReadPermissions:(nullable NSArray PF_GENERIC(NSString *)*)readPermissions
publishPermissions:(nullable NSArray PF_GENERIC(NSString *)*)publishPermissions {
return [self authenticateAsyncWithReadPermissions:readPermissions
publishPermissions:publishPermissions
fromViewComtroller:[PFFacebookPrivateUtilities applicationTopViewController]];
}

- (BFTask PF_GENERIC(NSDictionary<NSString *, NSString *>*)*)authenticateAsyncWithReadPermissions:(nullable NSArray PF_GENERIC(NSString *)*)readPermissions
publishPermissions:(nullable NSArray PF_GENERIC(NSString *)*)publishPermissions
fromViewComtroller:(UIViewController *)viewController {
return [BFTask taskWithError:[NSError pffb_invalidFacebookSessionError]];
}

///--------------------------------------
#pragma mark - PFUserAuthenticationDelegate
///--------------------------------------

- (BOOL)restoreAuthenticationWithAuthData:(nullable NSDictionary PF_GENERIC(NSString *, NSString *)*)authData {
FBSDKAccessToken *token = [PFFacebookPrivateUtilities facebookAccessTokenFromUserAuthenticationData:authData];
if (!token) {
return !authData; // Only deauthenticate if authData was nil, otherwise - return failure (`NO`).
}

FBSDKAccessToken *currentToken = [FBSDKAccessToken currentAccessToken];
// Do not reset the current token if we have the same token already set.
if (![currentToken.userID isEqualToString:token.userID] ||
![currentToken.tokenString isEqualToString:token.tokenString]) {
[FBSDKAccessToken setCurrentAccessToken:token];
}

return YES;
}

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Copyright (c) 2015-present, Parse, LLC.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/

#import <Foundation/Foundation.h>

#import <FBSDKLoginKit/FBSDKLoginManager.h>

#import <Parse/PFConstants.h>
#import <Parse/PFUser.h>

#import "PFFacebookAuthenticationProvider.h"

@class BFTask PF_GENERIC(__covariant BFGenericType);

NS_ASSUME_NONNULL_BEGIN

@interface PFFacebookMobileAuthenticationProvider : PFFacebookAuthenticationProvider

@property (nonatomic, strong, readonly) FBSDKLoginManager *loginManager;

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/**
* Copyright (c) 2015-present, Parse, LLC.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/

#import "PFFacebookMobileAuthenticationProvider.h"
#import "PFFacebookMobileAuthenticationProvider_Private.h"

#import <Bolts/BFTask.h>
#import <Bolts/BFTaskCompletionSource.h>

#import <FBSDKCoreKit/FBSDKAccessToken.h>
#import <FBSDKCoreKit/FBSDKSettings.h>

#import <FBSDKLoginKit/FBSDKLoginManagerLoginResult.h>

#import <Parse/PFConstants.h>

#import "PFFacebookPrivateUtilities.h"

@implementation PFFacebookMobileAuthenticationProvider

///--------------------------------------
#pragma mark - Init
///--------------------------------------

- (instancetype)initWithApplication:(UIApplication *)application
launchOptions:(nullable NSDictionary *)launchOptions {
self = [super initWithApplication:application launchOptions:launchOptions];
if (!self) return nil;

_loginManager = [[FBSDKLoginManager alloc] init];

return self;
}

///--------------------------------------
#pragma mark - Authenticate
///--------------------------------------

- (BFTask PF_GENERIC(NSDictionary<NSString *, NSString *>*)*)authenticateAsyncWithReadPermissions:(nullable NSArray PF_GENERIC(NSString *) *)readPermissions
publishPermissions:(nullable NSArray PF_GENERIC(NSString *) *)publishPermissions
fromViewComtroller:(UIViewController *)viewController {
if (readPermissions && publishPermissions) {
NSException *exception = [NSException exceptionWithName:NSInvalidArgumentException
reason:@"Read permissions are not permitted to be requested with publish permissions."
userInfo:nil];
return [BFTask taskWithException:exception];
}

BFTaskCompletionSource *taskCompletionSource = [BFTaskCompletionSource taskCompletionSource];
FBSDKLoginManagerRequestTokenHandler resultHandler = ^(FBSDKLoginManagerLoginResult *result, NSError *error) {
if (result.isCancelled) {
[taskCompletionSource cancel];
} else if (error) {
taskCompletionSource.error = error;
} else {
taskCompletionSource.result = [PFFacebookPrivateUtilities userAuthenticationDataFromAccessToken:result.token];
}
};
if (publishPermissions) {
[self.loginManager logInWithPublishPermissions:publishPermissions
fromViewController:viewController
handler:resultHandler];
} else {
[self.loginManager logInWithReadPermissions:readPermissions
fromViewController:viewController
handler:resultHandler];
}
return taskCompletionSource.task;
}

///--------------------------------------
#pragma mark - PFUserAuthenticationDelegate
///--------------------------------------

- (BOOL)restoreAuthenticationWithAuthData:(nullable NSDictionary PF_GENERIC(NSString *, NSString *) *)authData {
if (!authData) {
[self.loginManager logOut];
}
return [super restoreAuthenticationWithAuthData:authData];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,12 @@

#import <FBSDKLoginKit/FBSDKLoginManager.h>

#import "PFFacebookAuthenticationProvider.h"
#import "PFFacebookMobileAuthenticationProvider.h"

@class FBSDKAccessToken;

@interface PFFacebookAuthenticationProvider ()
@interface PFFacebookMobileAuthenticationProvider ()

@property (nonatomic, strong, readwrite) FBSDKLoginManager *loginManager;

+ (NSDictionary *)_userAuthenticationDataWithFacebookUserId:(NSString *)userId
accessToken:(NSString *)accessToken
expirationDate:(NSDate *)expirationDate;
+ (NSDictionary *)_userAuthenticationDataFromAccessToken:(FBSDKAccessToken *)token;

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Copyright (c) 2015-present, Parse, LLC.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/

#import <Foundation/Foundation.h>

#import "PFFacebookAuthenticationProvider.h"

@interface PFFacebookDeviceAuthenticationProvider : PFFacebookAuthenticationProvider
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally, I hate the name 'device' to refer to tvOS, but seeing as its FBSDKs decision, we really should keep it that way I suppose.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup. Naming here is totally influenced by FBSDK.


@end
Loading