- add client custom identifier to save credentials

This commit is contained in:
giuseppenuc committed 2019-01-08 14:55:10 +01:00
1 parent 99e06e67db
commit 1629110349
466 files changed
+5976 -26033

No files matched your search

@@ -1,96 +0,0 @@
// 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.
#import <Foundation/Foundation.h>
#import <FBSDKShareKit/FBSDKAppGroupContent.h>
@protocol FBSDKAppGroupAddDialogDelegate;
/**
@warning App and game groups are being deprecated. See https://developers.facebook.com/docs/games/services/game-groups for more information.
*/
__attribute__ ((deprecated))
@interface FBSDKAppGroupAddDialog : NSObject
/**
@warning App and game groups are being deprecated. See https://developers.facebook.com/docs/games/services/game-groups for more information.
*/
+ (instancetype)showWithContent:(FBSDKAppGroupContent *)content
delegate:(id<FBSDKAppGroupAddDialogDelegate>)delegate __attribute__ ((deprecated));
/**
@warning App and game groups are being deprecated. See https://developers.facebook.com/docs/games/services/game-groups for more information.
*/
@property (nonatomic, weak) id<FBSDKAppGroupAddDialogDelegate> delegate __attribute__ ((deprecated));
/**
@warning App and game groups are being deprecated. See https://developers.facebook.com/docs/games/services/game-groups for more information.
*/
@property (nonatomic, copy) FBSDKAppGroupContent *content __attribute__ ((deprecated));
/**
@warning App and game groups are being deprecated. See https://developers.facebook.com/docs/games/services/game-groups for more information.
*/
- (BOOL)canShow __attribute__ ((deprecated));
/**
@warning App and game groups are being deprecated. See https://developers.facebook.com/docs/games/services/game-groups for more information.
*/
- (BOOL)show __attribute__ ((deprecated));
/**
@warning App and game groups are being deprecated. See https://developers.facebook.com/docs/games/services/game-groups for more information.
*/
- (BOOL)validateWithError:(NSError *__autoreleasing *)errorRef __attribute__ ((deprecated));
@end
/**
@warning App and game groups are being deprecated. See https://developers.facebook.com/docs/games/services/game-groups for more information.
*/
__attribute__ ((deprecated))
@protocol FBSDKAppGroupAddDialogDelegate <NSObject>
/**
@warning App and game groups are being deprecated. See https://developers.facebook.com/docs/games/services/game-groups for more information.
*/
- (void)appGroupAddDialog:(FBSDKAppGroupAddDialog *)appGroupAddDialog didCompleteWithResults:(NSDictionary *)results __attribute__ ((deprecated));
/**
@warning App and game groups are being deprecated. See https://developers.facebook.com/docs/games/services/game-groups for more information.
*/
- (void)appGroupAddDialog:(FBSDKAppGroupAddDialog *)appGroupAddDialog didFailWithError:(NSError *)error __attribute__ ((deprecated));
/**
@warning App and game groups are being deprecated. See https://developers.facebook.com/docs/games/services/game-groups for more information.
*/
- (void)appGroupAddDialogDidCancel:(FBSDKAppGroupAddDialog *)appGroupAddDialog __attribute__ ((deprecated));
@end
@@ -1,185 +0,0 @@
// 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.
#import "FBSDKAppGroupAddDialog.h"
#import "FBSDKCoreKit+Internal.h"
#import "FBSDKShareConstants.h"
#import "FBSDKShareError.h"
#import "FBSDKShareUtility.h"
@interface FBSDKAppGroupAddDialog () <FBSDKWebDialogDelegate>
@end
@implementation FBSDKAppGroupAddDialog
{
FBSDKWebDialog *_webDialog;
}
#define FBSDK_APP_GROUP_CREATE_METHOD_NAME @"game_group_create"
#pragma mark - Class Methods
+ (instancetype)showWithContent:(FBSDKAppGroupContent *)content
delegate:(id<FBSDKAppGroupAddDialogDelegate>)delegate
{
FBSDKAppGroupAddDialog *dialog = [[self alloc] init];
dialog.content = content;
dialog.delegate = delegate;
[dialog show];
return dialog;
}
#pragma mark - Object Lifecycle
- (instancetype)init
{
if ((self = [super init])) {
_webDialog = [[FBSDKWebDialog alloc] init];
_webDialog.delegate = self;
_webDialog.name = FBSDK_APP_GROUP_CREATE_METHOD_NAME;
}
return self;
}
- (void)dealloc
{
_webDialog.delegate = nil;
}
#pragma mark - Public Methods
- (BOOL)canShow
{
return YES;
}
- (BOOL)show
{
NSError *error;
if (![self canShow]) {
error = [FBSDKShareError errorWithCode:FBSDKShareDialogNotAvailableErrorCode
message:@"App group create dialog is not available."];
[_delegate appGroupAddDialog:self didFailWithError:error];
return NO;
}
if (![self validateWithError:&error]) {
[_delegate appGroupAddDialog:self didFailWithError:error];
return NO;
}
FBSDKAppGroupContent *content = self.content;
NSMutableDictionary *parameters = [[NSMutableDictionary alloc] init];
[FBSDKInternalUtility dictionary:parameters setObject:content.name forKey:@"name"];
[FBSDKInternalUtility dictionary:parameters setObject:content.groupDescription forKey:@"description"];
[FBSDKInternalUtility dictionary:parameters
setObject:NSStringFromFBSDKAppGroupPrivacy(content.privacy)
forKey:@"privacy"];
_webDialog.parameters = parameters;
[_webDialog show];
[FBSDKInternalUtility registerTransientObject:self];
return YES;
}
- (BOOL)validateWithError:(NSError *__autoreleasing *)errorRef
{
FBSDKAppGroupContent *content = self.content;
if (!content) {
if (errorRef != NULL) {
*errorRef = [FBSDKShareError requiredArgumentErrorWithName:@"content" message:nil];
}
return NO;
}
if (![content.name length]) {
if (errorRef != NULL) {
*errorRef = [FBSDKShareError requiredArgumentErrorWithName:@"name" message:nil];
}
return NO;
}
if (![content.groupDescription length]) {
if (errorRef != NULL) {
*errorRef = [FBSDKShareError requiredArgumentErrorWithName:@"groupDescription" message:nil];
}
return NO;
}
if (errorRef != NULL) {
*errorRef = nil;
}
return YES;
}
#pragma mark - FBSDKWebDialogDelegate
- (void)webDialog:(FBSDKWebDialog *)webDialog didCompleteWithResults:(NSDictionary *)results
{
if (_webDialog != webDialog) {
return;
}
NSError *error = [FBSDKShareError errorWithCode:[FBSDKTypeUtility unsignedIntegerValue:results[@"error_code"]]
message:[FBSDKTypeUtility stringValue:results[@"error_message"]]];
[self _handleCompletionWithDialogResults:results error:error];
[FBSDKInternalUtility unregisterTransientObject:self];
}
- (void)webDialog:(FBSDKWebDialog *)webDialog didFailWithError:(NSError *)error
{
if (_webDialog != webDialog) {
return;
}
[self _handleCompletionWithDialogResults:nil error:error];
[FBSDKInternalUtility unregisterTransientObject:self];
}
- (void)webDialogDidCancel:(FBSDKWebDialog *)webDialog
{
if (_webDialog != webDialog) {
return;
}
[_delegate appGroupAddDialogDidCancel:self];
[FBSDKInternalUtility unregisterTransientObject:self];
}
#pragma mark - Helper Methods
- (void)_handleCompletionWithDialogResults:(NSDictionary *)results error:(NSError *)error
{
if (!_delegate) {
return;
}
switch (error.code) {
case 0:{
[_delegate appGroupAddDialog:self didCompleteWithResults:results];
break;
}
case 4201:{
[_delegate appGroupAddDialogDidCancel:self];
break;
}
default:{
[_delegate appGroupAddDialog:self didFailWithError:error];
break;
}
}
if (error) {
return;
} else {
}
}
@end
@@ -1,68 +0,0 @@
// 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.
#import <Foundation/Foundation.h>
#import <FBSDKCoreKit/FBSDKCopying.h>
#import <FBSDKCoreKit/FBSDKMacros.h>
/**
NS_ENUM(NSUInteger, FBSDKAppGroupPrivacy)
Specifies the privacy of a group.
*/
typedef NS_ENUM(NSUInteger, FBSDKAppGroupPrivacy)
{
/** Anyone can see the group, who's in it and what members post. */
FBSDKAppGroupPrivacyOpen = 0,
/** Anyone can see the group and who's in it, but only members can see posts. */
FBSDKAppGroupPrivacyClosed,
};
/**
Converts an FBSDKAppGroupPrivacy to an NSString.
*/
FBSDK_EXTERN NSString *NSStringFromFBSDKAppGroupPrivacy(FBSDKAppGroupPrivacy privacy);
/**
A model for creating an app group.
*/
@interface FBSDKAppGroupContent : NSObject <FBSDKCopying, NSSecureCoding>
/**
The description of the group.
*/
@property (nonatomic, copy) NSString *groupDescription;
/**
The name of the group.
*/
@property (nonatomic, copy) NSString *name;
/**
The privacy for the group.
*/
@property (nonatomic, assign) FBSDKAppGroupPrivacy privacy;
/**
Compares the receiver to another app group content.
@param content The other content
@return YES if the receiver's values are equal to the other content's values; otherwise NO
*/
- (BOOL)isEqualToAppGroupContent:(FBSDKAppGroupContent *)content;
@end
@@ -1,109 +0,0 @@
// 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.
#import "FBSDKAppGroupContent.h"
#import "FBSDKCoreKit+Internal.h"
#import "FBSDKShareUtility.h"
#define FBSDK_APP_GROUP_CONTENT_GROUP_DESCRIPTION_KEY @"groupDescription"
#define FBSDK_APP_GROUP_CONTENT_NAME_KEY @"name"
#define FBSDK_APP_GROUP_CONTENT_PRIVACY_KEY @"privacy"
NSString *NSStringFromFBSDKAppGroupPrivacy(FBSDKAppGroupPrivacy privacy)
{
switch (privacy) {
case FBSDKAppGroupPrivacyClosed:{
return @"closed";
}
case FBSDKAppGroupPrivacyOpen:{
return @"open";
}
}
}
@implementation FBSDKAppGroupContent
#pragma mark - Equality
- (NSUInteger)hash
{
NSUInteger subhashes[] = {
[_groupDescription hash],
[_name hash],
_privacy,
};
return [FBSDKMath hashWithIntegerArray:subhashes count:sizeof(subhashes) / sizeof(subhashes[0])];
}
- (BOOL)isEqual:(id)object
{
if (self == object) {
return YES;
}
if (![object isKindOfClass:[FBSDKAppGroupContent class]]) {
return NO;
}
return [self isEqualToAppGroupContent:(FBSDKAppGroupContent *)object];
}
- (BOOL)isEqualToAppGroupContent:(FBSDKAppGroupContent *)content
{
return (content &&
(_privacy == content.privacy) &&
[FBSDKInternalUtility object:_name isEqualToObject:content.name] &&
[FBSDKInternalUtility object:_groupDescription isEqualToObject:content.groupDescription]);
}
#pragma mark - NSCoding
+ (BOOL)supportsSecureCoding
{
return YES;
}
- (id)initWithCoder:(NSCoder *)decoder
{
if ((self = [self init])) {
_groupDescription = [decoder decodeObjectOfClass:[NSString class]
forKey:FBSDK_APP_GROUP_CONTENT_GROUP_DESCRIPTION_KEY];
_name = [decoder decodeObjectOfClass:[NSString class] forKey:FBSDK_APP_GROUP_CONTENT_PRIVACY_KEY];
_privacy = [decoder decodeIntegerForKey:FBSDK_APP_GROUP_CONTENT_PRIVACY_KEY];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)encoder
{
[encoder encodeObject:_groupDescription forKey:FBSDK_APP_GROUP_CONTENT_GROUP_DESCRIPTION_KEY];
[encoder encodeObject:_name forKey:FBSDK_APP_GROUP_CONTENT_NAME_KEY];
[encoder encodeInteger:_privacy forKey:FBSDK_APP_GROUP_CONTENT_PRIVACY_KEY];
}
#pragma mark - NSCopying
- (id)copyWithZone:(NSZone *)zone
{
FBSDKAppGroupContent *copy = [[FBSDKAppGroupContent alloc] init];
copy->_groupDescription = [_groupDescription copy];
copy->_name = [_name copy];
copy->_privacy = _privacy;
return copy;
}
@end
@@ -1,92 +0,0 @@
// 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.
#import <Foundation/Foundation.h>
@protocol FBSDKAppGroupJoinDialogDelegate;
/**
@warning App and game groups are being deprecated. See https://developers.facebook.com/docs/games/services/game-groups for more information.
*/
__attribute__ ((deprecated))
@interface FBSDKAppGroupJoinDialog : NSObject
/**
@warning App and game groups are being deprecated. See https://developers.facebook.com/docs/games/services/game-groups for more information.
*/
+ (instancetype)showWithGroupID:(NSString *)groupID
delegate:(id<FBSDKAppGroupJoinDialogDelegate>)delegate __attribute__ ((deprecated));
/**
@warning App and game groups are being deprecated. See https://developers.facebook.com/docs/games/services/game-groups for more information. */
@property (nonatomic, weak) id<FBSDKAppGroupJoinDialogDelegate> delegate __attribute__ ((deprecated));
/**
@warning App and game groups are being deprecated. See https://developers.facebook.com/docs/games/services/game-groups for more information. */
@property (nonatomic, copy) NSString *groupID __attribute__ ((deprecated));
/**
@warning App and game groups are being deprecated. See https://developers.facebook.com/docs/games/services/game-groups for more information.
*/
- (BOOL)canShow __attribute__ ((deprecated));
/**
@warning App and game groups are being deprecated. See https://developers.facebook.com/docs/games/services/game-groups for more information.
*/
- (BOOL)show __attribute__ ((deprecated));
/**
@warning App and game groups are being deprecated. See https://developers.facebook.com/docs/games/services/game-groups for more information.
*/
- (BOOL)validateWithError:(NSError *__autoreleasing *)errorRef __attribute__ ((deprecated));
@end
/**
@warning App and game groups are being deprecated. See https://developers.facebook.com/docs/games/services/game-groups for more information.
*/
__attribute__ ((deprecated))
@protocol FBSDKAppGroupJoinDialogDelegate <NSObject>
/**
@warning App and game groups are being deprecated. See https://developers.facebook.com/docs/games/services/game-groups for more information.
*/
- (void)appGroupJoinDialog:(FBSDKAppGroupJoinDialog *)appGroupJoinDialog didCompleteWithResults:(NSDictionary *)results __attribute__ ((deprecated));
/**
@warning App and game groups are being deprecated. See https://developers.facebook.com/docs/games/services/game-groups for more information.
*/
- (void)appGroupJoinDialog:(FBSDKAppGroupJoinDialog *)appGroupJoinDialog didFailWithError:(NSError *)error __attribute__ ((deprecated));
/**
@warning App and game groups are being deprecated. See https://developers.facebook.com/docs/games/services/game-groups for more information.
*/
- (void)appGroupJoinDialogDidCancel:(FBSDKAppGroupJoinDialog *)appGroupJoinDialog __attribute__ ((deprecated));
@end
@@ -1,167 +0,0 @@
// 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.
#import "FBSDKAppGroupJoinDialog.h"
#import "FBSDKCoreKit+Internal.h"
#import "FBSDKShareConstants.h"
#import "FBSDKShareError.h"
#import "FBSDKShareUtility.h"
@interface FBSDKAppGroupJoinDialog () <FBSDKWebDialogDelegate>
@end
@implementation FBSDKAppGroupJoinDialog
{
FBSDKWebDialog *_webDialog;
}
#define FBSDK_APP_GROUP_JOIN_METHOD_NAME @"game_group_join"
#pragma mark - Class Methods
+ (instancetype)showWithGroupID:(NSString *)groupID
delegate:(id<FBSDKAppGroupJoinDialogDelegate>)delegate
{
FBSDKAppGroupJoinDialog *dialog = [[self alloc] init];
dialog.groupID = groupID;
dialog.delegate = delegate;
[dialog show];
return dialog;
}
#pragma mark - Object Lifecycle
- (instancetype)init
{
if ((self = [super init])) {
_webDialog = [[FBSDKWebDialog alloc] init];
_webDialog.delegate = self;
_webDialog.name = FBSDK_APP_GROUP_JOIN_METHOD_NAME;
}
return self;
}
- (void)dealloc
{
_webDialog.delegate = nil;
}
#pragma mark - Public Methods
- (BOOL)canShow
{
return YES;
}
- (BOOL)show
{
NSError *error;
if (![self canShow]) {
error = [FBSDKShareError errorWithCode:FBSDKShareDialogNotAvailableErrorCode
message:@"App group join dialog is not available."];
[_delegate appGroupJoinDialog:self didFailWithError:error];
return NO;
}
if (![self validateWithError:&error]) {
[_delegate appGroupJoinDialog:self didFailWithError:error];
return NO;
}
NSMutableDictionary *parameters = [[NSMutableDictionary alloc] init];
[FBSDKInternalUtility dictionary:parameters setObject:self.groupID forKey:@"id"];
_webDialog.parameters = parameters;
[_webDialog show];
[FBSDKInternalUtility registerTransientObject:self];
return YES;
}
- (BOOL)validateWithError:(NSError *__autoreleasing *)errorRef
{
if (![self.groupID length]) {
if (errorRef != NULL) {
*errorRef = [FBSDKShareError requiredArgumentErrorWithName:@"groupID" message:nil];
}
return NO;
}
if (errorRef != NULL) {
*errorRef = nil;
}
return YES;
}
#pragma mark - FBSDKWebDialogDelegate
- (void)webDialog:(FBSDKWebDialog *)webDialog didCompleteWithResults:(NSDictionary *)results
{
if (_webDialog != webDialog) {
return;
}
NSError *error = [FBSDKShareError errorWithCode:[FBSDKTypeUtility unsignedIntegerValue:results[@"error_code"]]
message:[FBSDKTypeUtility stringValue:results[@"error_message"]]];
[self _handleCompletionWithDialogResults:results error:error];
[FBSDKInternalUtility unregisterTransientObject:self];
}
- (void)webDialog:(FBSDKWebDialog *)webDialog didFailWithError:(NSError *)error
{
if (_webDialog != webDialog) {
return;
}
[self _handleCompletionWithDialogResults:nil error:error];
[FBSDKInternalUtility unregisterTransientObject:self];
}
- (void)webDialogDidCancel:(FBSDKWebDialog *)webDialog
{
if (_webDialog != webDialog) {
return;
}
[_delegate appGroupJoinDialogDidCancel:self];
[FBSDKInternalUtility unregisterTransientObject:self];
}
#pragma mark - Helper Methods
- (void)_handleCompletionWithDialogResults:(NSDictionary *)results error:(NSError *)error
{
if (!_delegate) {
return;
}
switch (error.code) {
case 0:{
[_delegate appGroupJoinDialog:self didCompleteWithResults:results];
break;
}
case 4201:{
[_delegate appGroupJoinDialogDidCancel:self];
break;
}
default:{
[_delegate appGroupJoinDialog:self didFailWithError:error];
break;
}
}
if (error) {
return;
} else {
}
}
@end
@@ -1,96 +0,0 @@
// 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.
#import <Foundation/Foundation.h>
#import <FBSDKCoreKit/FBSDKCopying.h>
#import <FBSDKShareKit/FBSDKSharingValidation.h>
/**
NS_ENUM(NSUInteger, FBSDKAppInviteDestination)
Specifies the privacy of a group.
*/
typedef NS_ENUM(NSUInteger, FBSDKAppInviteDestination)
{
/** Deliver to Facebook. */
FBSDKAppInviteDestinationFacebook = 0,
/** Deliver to Messenger. */
FBSDKAppInviteDestinationMessenger,
};
/**
A model for app invite.
*/
@interface FBSDKAppInviteContent : NSObject <FBSDKCopying, FBSDKSharingValidation, NSSecureCoding>
/**
A URL to a preview image that will be displayed with the app invite
This is optional. If you don't include it a fallback image will be used.
*/
@property (nonatomic, copy) NSURL *appInvitePreviewImageURL;
/**
An app link target that will be used as a target when the user accept the invite.
This is a requirement.
*/
@property (nonatomic, copy) NSURL *appLinkURL;
/**
@warning Use `appInvitePreviewImageURL` instead.
*/
@property (nonatomic, copy) NSURL *previewImageURL __attribute__ ((deprecated("use appInvitePreviewImageURL instead")));
/**
Promotional code to be displayed while sending and receiving the invite.
This is optional. This can be between 0 and 10 characters long and can contain
alphanumeric characters only. To set a promo code, you need to set promo text.
*/
@property (nonatomic, copy) NSString *promotionCode;
/**
Promotional text to be displayed while sending and receiving the invite.
This is optional. This can be between 0 and 80 characters long and can contain
alphanumeric and spaces only.
*/
@property (nonatomic, copy) NSString *promotionText;
/**
Destination for the app invite.
This is optional and for declaring destination of the invite.
*/
@property FBSDKAppInviteDestination destination;
/**
Compares the receiver to another app invite content.
@param content The other content
@return YES if the receiver's values are equal to the other content's values; otherwise NO
*/
- (BOOL)isEqualToAppInviteContent:(FBSDKAppInviteContent *)content;
@end
@@ -1,177 +0,0 @@
// 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.
#import "FBSDKAppInviteContent.h"
#import "FBSDKCoreKit+Internal.h"
#import "FBSDKShareUtility.h"
#define FBSDK_APP_INVITE_CONTENT_APP_LINK_URL_KEY @"appLinkURL"
#define FBSDK_APP_INVITE_CONTENT_PREVIEW_IMAGE_KEY @"previewImage"
#define FBSDK_APP_INVITE_CONTENT_PROMO_CODE_KEY @"promoCode"
#define FBSDK_APP_INVITE_CONTENT_PROMO_TEXT_KEY @"promoText"
#define FBSDK_APP_INVITE_CONTENT_DESTINATION_KEY @"destination"
@implementation FBSDKAppInviteContent
- (NSURL *)previewImageURL
{
return self.appInvitePreviewImageURL;
}
- (void)setPreviewImageURL:(NSURL *)previewImageURL
{
self.appInvitePreviewImageURL = previewImageURL;
}
#pragma mark - FBSDKSharingValidation
- (BOOL)validateWithOptions:(FBSDKShareBridgeOptions)bridgeOptions error:(NSError *__autoreleasing *)errorRef
{
return ([FBSDKShareUtility validateRequiredValue:_appLinkURL name:@"appLinkURL" error:errorRef] &&
[FBSDKShareUtility validateNetworkURL:_appLinkURL name:@"appLinkURL" error:errorRef] &&
[FBSDKShareUtility validateNetworkURL:_appInvitePreviewImageURL name:@"appInvitePreviewImageURL" error:errorRef] &&
[self _validatePromoCodeWithError:errorRef]);
}
- (BOOL)_validatePromoCodeWithError:(NSError *__autoreleasing *)errorRef
{
if ([_promotionText length] > 0 || [_promotionCode length] > 0) {
NSMutableCharacterSet *alphanumericWithSpaces = [NSMutableCharacterSet alphanumericCharacterSet];
[alphanumericWithSpaces formUnionWithCharacterSet:[NSCharacterSet whitespaceCharacterSet]];
// Check for validity of promo text and promo code.
if (!([_promotionText length] > 0 && [_promotionText length] <= 80)) {
if (errorRef != NULL) {
*errorRef = [FBSDKError invalidArgumentErrorWithName:@"promotionText" value:_promotionText message:@"Invalid value for promotionText, promotionText has to be between 1 and 80 characters long."];
}
return NO;
}
if (!([_promotionCode length] <= 10)) {
if (errorRef != NULL) {
*errorRef = [FBSDKError invalidArgumentErrorWithName:@"promotionCode" value:_promotionCode message:@"Invalid value for promotionCode, promotionCode has to be between 0 and 10 characters long and is required when promoCode is set."];
}
return NO;
}
if ([_promotionText rangeOfCharacterFromSet:[alphanumericWithSpaces invertedSet]].location != NSNotFound) {
if (errorRef != NULL) {
*errorRef = [FBSDKError invalidArgumentErrorWithName:@"promotionText" value:_promotionText message:@"Invalid value for promotionText, promotionText can contain only alphanumeric characters and spaces."];
}
return NO;
}
if ([_promotionCode length] > 0 && [_promotionCode rangeOfCharacterFromSet:[alphanumericWithSpaces invertedSet]].location != NSNotFound) {
if (errorRef != NULL) {
*errorRef = [FBSDKError invalidArgumentErrorWithName:@"promotionCode" value:_promotionCode message:@"Invalid value for promotionCode, promotionCode can contain only alphanumeric characters and spaces."];
}
return NO;
}
}
if (errorRef != NULL) {
*errorRef = nil;
}
return YES;
}
#pragma mark - Equality
- (NSUInteger)hash
{
NSUInteger subhashes[] = {
[_appLinkURL hash],
[_appInvitePreviewImageURL hash],
[_promotionCode hash],
[_promotionText hash],
};
return [FBSDKMath hashWithIntegerArray:subhashes count:sizeof(subhashes) / sizeof(subhashes[0])];
}
- (BOOL)isEqual:(id)object
{
if (self == object) {
return YES;
}
if (![object isKindOfClass:[FBSDKAppInviteContent class]]) {
return NO;
}
return [self isEqualToAppInviteContent:(FBSDKAppInviteContent *)object];
}
- (BOOL)isEqualToAppInviteContent:(FBSDKAppInviteContent *)content
{
return (content &&
[FBSDKInternalUtility object:_appLinkURL isEqualToObject:content.appLinkURL] &&
[FBSDKInternalUtility object:_appInvitePreviewImageURL isEqualToObject:content.appInvitePreviewImageURL] &&
[FBSDKInternalUtility object:_promotionText isEqualToObject:content.promotionText] &&
[FBSDKInternalUtility object:_promotionCode isEqualToObject:content.promotionText] &&
_destination == content.destination
);
}
#pragma mark - NSCoding
+ (BOOL)supportsSecureCoding
{
return YES;
}
- (id)initWithCoder:(NSCoder *)decoder
{
if ((self = [self init])) {
_appLinkURL = [decoder decodeObjectOfClass:[NSURL class] forKey:FBSDK_APP_INVITE_CONTENT_APP_LINK_URL_KEY];
_appInvitePreviewImageURL = [decoder decodeObjectOfClass:[NSURL class] forKey:FBSDK_APP_INVITE_CONTENT_PREVIEW_IMAGE_KEY];
_promotionCode = [decoder decodeObjectOfClass:[NSString class] forKey:
FBSDK_APP_INVITE_CONTENT_PROMO_CODE_KEY];
_promotionText = [decoder decodeObjectOfClass:[NSString class] forKey:
FBSDK_APP_INVITE_CONTENT_PROMO_TEXT_KEY];
_destination = [decoder decodeIntegerForKey:
FBSDK_APP_INVITE_CONTENT_DESTINATION_KEY];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)encoder
{
[encoder encodeObject:_appLinkURL forKey:FBSDK_APP_INVITE_CONTENT_APP_LINK_URL_KEY];
[encoder encodeObject:_appInvitePreviewImageURL forKey:FBSDK_APP_INVITE_CONTENT_PREVIEW_IMAGE_KEY];
[encoder encodeObject:_promotionCode forKey:FBSDK_APP_INVITE_CONTENT_PROMO_CODE_KEY];
[encoder encodeObject:_promotionText forKey:FBSDK_APP_INVITE_CONTENT_PROMO_TEXT_KEY];
[encoder encodeInt:_destination forKey:FBSDK_APP_INVITE_CONTENT_DESTINATION_KEY];
}
#pragma mark - NSCopying
- (id)copyWithZone:(NSZone *)zone
{
FBSDKAppInviteContent *copy = [[FBSDKAppInviteContent alloc] init];
copy->_appLinkURL = [_appLinkURL copy];
copy->_appInvitePreviewImageURL = [_appInvitePreviewImageURL copy];
copy->_promotionText = [_promotionText copy];
copy->_promotionCode = [_promotionCode copy];
copy->_destination = _destination;
return copy;
}
@end
@@ -1,118 +0,0 @@
// 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.
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <FBSDKShareKit/FBSDKAppInviteContent.h>
@protocol FBSDKAppInviteDialogDelegate;
/**
A dialog for sending App Invites.
*/
@interface FBSDKAppInviteDialog : NSObject
/**
Convenience method to show a FBSDKAppInviteDialog
@param viewController A UIViewController to present the dialog from.
@param content The content for the app invite.
@param delegate The receiver's delegate.
@warning This method is deprecated.
*/
+ (instancetype)showFromViewController:(UIViewController *)viewController
withContent:(FBSDKAppInviteContent *)content
delegate:(id<FBSDKAppInviteDialogDelegate>)delegate
__attribute__ ((deprecated("App Invites no longer supported")));
/**
@warning use showFromViewController:withContent:delegate: instead
*/
+ (instancetype)showWithContent:(FBSDKAppInviteContent *)content delegate:(id<FBSDKAppInviteDialogDelegate>)delegate
__attribute__ ((deprecated("use showFromViewController:withContent:delegate: instead")));
/**
A UIViewController to present the dialog from.
If not specified, the top most view controller will be automatically determined as best as possible.
*/
@property (nonatomic, weak) UIViewController *fromViewController;
/**
The receiver's delegate or nil if it doesn't have a delegate.
*/
@property (nonatomic, weak) id<FBSDKAppInviteDialogDelegate> delegate;
/**
The content for app invite.
*/
@property (nonatomic, copy) FBSDKAppInviteContent *content;
/**
A Boolean value that indicates whether the receiver can initiate an app invite.
May return NO if the appropriate Facebook app is not installed and is required or an access token is
required but not available. This method does not validate the content on the receiver, so this can be checked before
building up the content.
@see validateWithError:
@return YES if the receiver can show the dialog, otherwise NO.
*/
- (BOOL)canShow;
/**
Begins the app invite from the receiver.
@return YES if the receiver was able to show the dialog, otherwise NO.
*/
- (BOOL)show;
/**
Validates the content on the receiver.
@param errorRef If an error occurs, upon return contains an NSError object that describes the problem.
@return YES if the content is valid, otherwise NO.
*/
- (BOOL)validateWithError:(NSError *__autoreleasing *)errorRef;
@end
/**
A delegate for FBSDKAppInviteDialog.
The delegate is notified with the results of the app invite as long as the application has permissions to
receive the information. For example, if the person is not signed into the containing app, the shower may not be able
to distinguish between completion of an app invite and cancellation.
*/
@protocol FBSDKAppInviteDialogDelegate <NSObject>
/**
Sent to the delegate when the app invite completes without error.
@param appInviteDialog The FBSDKAppInviteDialog that completed.
@param results The results from the dialog. This may be nil or empty.
*/
- (void)appInviteDialog:(FBSDKAppInviteDialog *)appInviteDialog didCompleteWithResults:(NSDictionary *)results;
/**
Sent to the delegate when the app invite encounters an error.
@param appInviteDialog The FBSDKAppInviteDialog that completed.
@param error The error.
*/
- (void)appInviteDialog:(FBSDKAppInviteDialog *)appInviteDialog didFailWithError:(NSError *)error;
@end
@@ -1,83 +0,0 @@
// 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.
#import "FBSDKAppInviteDialog.h"
#import "FBSDKCoreKit+Internal.h"
#import "FBSDKShareConstants.h"
#import "FBSDKShareDefines.h"
#import "FBSDKShareError.h"
#import "FBSDKShareUtility.h"
@implementation FBSDKAppInviteDialog
#define FBSDK_APP_INVITE_METHOD_MIN_VERSION @"20140410"
#define FBSDK_APP_INVITE_METHOD_NAME @"appinvites"
+ (void)initialize
{
if ([FBSDKAppInviteDialog class] == self) {
[FBSDKInternalUtility checkRegisteredCanOpenURLScheme:FBSDK_CANOPENURL_FACEBOOK];
// ensure that we have updated the dialog configs if we haven't already
[FBSDKServerConfigurationManager loadServerConfigurationWithCompletionBlock:NULL];
}
}
#pragma mark - Class Methods
+ (instancetype)showWithContent:(FBSDKAppInviteContent *)content delegate:(id<FBSDKAppInviteDialogDelegate>)delegate
{
return [self showFromViewController:nil withContent:content delegate:delegate];
}
+ (instancetype)showFromViewController:(UIViewController *)viewController
withContent:(FBSDKAppInviteContent *)content
delegate:(id<FBSDKAppInviteDialogDelegate>)delegate;
{
return nil;
}
#pragma mark - Public Methods
- (BOOL)canShow
{
return NO;
}
- (BOOL)show
{
return NO;
}
- (BOOL)validateWithError:(NSError *__autoreleasing *)errorRef
{
if (![FBSDKShareUtility validateRequiredValue:self.content name:@"content" error:errorRef]) {
return NO;
}
if ([self.content respondsToSelector:@selector(validateWithError:)]) {
return [self.content validateWithOptions:FBSDKShareBridgeOptionsDefault error:errorRef];
}
if (errorRef != NULL) {
*errorRef = [FBSDKShareError invalidArgumentErrorWithName:@"content" value:self.content message:nil];
}
return NO;
}
@end
@@ -1,57 +0,0 @@
// 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.
#import <Foundation/Foundation.h>
#import <FBSDKCoreKit/FBSDKCopying.h>
/**
* A container of arguments for a camera effect.
* An argument is a NSString identified by a NSString key.
*/
@interface FBSDKCameraEffectArguments : NSObject <FBSDKCopying, NSSecureCoding>
/**
Sets a string argument in the container.
@param string The argument
@param key The key for the argument
*/
- (void)setString:(NSString *)string forKey:(NSString *)key;
/**
Gets a string argument from the container.
@param key The key for the argument
@return The string value or nil
*/
- (NSString *)stringForKey:(NSString *)key;
/**
Sets a string array argument in the container.
@param array The array argument
@param key The key for the argument
*/
- (void)setArray:(NSArray<NSString *> *)array forKey:(NSString *)key;
/**
Gets an array argument from the container.
@param key The key for the argument
@return The array argument
*/
- (NSArray *)arrayForKey:(NSString *)key;
@end
@@ -1,177 +0,0 @@
// 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.
#import "FBSDKCameraEffectArguments.h"
#import "FBSDKCoreKit+Internal.h"
#import "FBSDKShareUtility.h"
static NSString *const FBSDKCameraEffectArgumentsArgumentsKey = @"arguments";
@implementation FBSDKCameraEffectArguments
{
NSMutableDictionary *_arguments;
}
#pragma mark - Object Lifecycle
- (instancetype)init
{
if ((self = [super init])) {
_arguments = [NSMutableDictionary new];
}
return self;
}
- (void)setString:(NSString *)string forKey:(NSString *)key
{
[self _setValue:[string copy] forKey:key];
}
- (NSString *)stringForKey:(NSString *)key
{
return [self _valueOfClass:[NSString class] forKey:key];
}
- (void)setArray:(NSArray<NSString *> *)array forKey:(NSString *)key
{
[self _setValue:[array copy] forKey:key];
}
- (NSArray *)arrayForKey:(NSString *)key
{
return [self _valueOfClass:[NSArray class] forKey:key];
}
- (NSDictionary *)allArguments
{
return _arguments;
}
#pragma mark - Equality
- (NSUInteger)hash
{
return [_arguments hash];
}
- (BOOL)isEqual:(id)object
{
if (self == object) {
return YES;
}
if (![object isKindOfClass:[FBSDKCameraEffectArguments class]]) {
return NO;
}
return [self isEqualToCameraEffectArguments:(FBSDKCameraEffectArguments *)object];
}
- (BOOL)isEqualToCameraEffectArguments:(FBSDKCameraEffectArguments *)object
{
return [FBSDKInternalUtility object:_arguments isEqualToObject:[object allArguments]];
}
#pragma mark - NSCoding
+ (BOOL)supportsSecureCoding
{
return YES;
}
- (id)initWithCoder:(NSCoder *)decoder
{
if ((self = [self init])) {
_arguments = [decoder decodeObjectOfClass:[NSMutableDictionary class]
forKey:FBSDKCameraEffectArgumentsArgumentsKey];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)encoder
{
[encoder encodeObject:_arguments forKey:FBSDKCameraEffectArgumentsArgumentsKey];
}
#pragma mark - NSCopying
- (id)copyWithZone:(NSZone *)zone
{
FBSDKCameraEffectArguments *copy = [FBSDKCameraEffectArguments new];
copy->_arguments = [_arguments copy];
return copy;
}
#pragma mark - Helper Methods
- (void)_setValue:(id)value forKey:(NSString *)key
{
[FBSDKCameraEffectArguments assertKey:key];
if (value) {
[FBSDKCameraEffectArguments assertValue:value];
_arguments[key] = value;
} else {
[_arguments removeObjectForKey:key];
}
}
- (id)_valueForKey:(NSString *)key
{
key = [FBSDKTypeUtility stringValue:key];
return (key ? [FBSDKTypeUtility objectValue:_arguments[key]] : nil);
}
- (id)_valueOfClass:(__unsafe_unretained Class)cls forKey:(NSString *)key
{
id value = [self _valueForKey:key];
return ([value isKindOfClass:cls] ? value : nil);
}
+ (void)assertKey:(id)key
{
if ([key isKindOfClass:[NSString class]]) {
return;
}
NSString *reason = [NSString stringWithFormat:@"Invalid key found in CameraEffectArguments: %@", key];
@throw [NSException exceptionWithName:NSInvalidArgumentException reason:reason userInfo:nil];
}
+ (void)assertValue:(id)value
{
BOOL isInvalid = NO;
if ([value isKindOfClass:[NSString class]]) {
// Strings are always valid.
} else if ([value isKindOfClass:[NSArray class]]) {
// Allow only string arrays.
for (id subValue in (NSArray *)value) {
if (![subValue isKindOfClass:[NSString class]]) {
isInvalid = YES;
break;
}
}
} else {
isInvalid = YES;
}
if (isInvalid) {
NSString *reason = [NSString stringWithFormat:@"Invalid value found in CameraEffectArguments: %@", value];
@throw [NSException exceptionWithName:NSInvalidArgumentException reason:reason userInfo:nil];
}
}
@end
@@ -1,43 +0,0 @@
// 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.
#import <UIKit/UIKit.h>
#import <FBSDKCoreKit/FBSDKCopying.h>
/**
* A container of textures for a camera effect.
* A texture for a camera effect is an UIImages identified by a NSString key.
*/
@interface FBSDKCameraEffectTextures : NSObject <FBSDKCopying, NSSecureCoding>
/**
Sets the image for a texture key.
@param image The UIImage for the texture
@param key The key for the texture
*/
- (void)setImage:(UIImage *)image forKey:(NSString *)key;
/**
Gets the image for a texture key.
@param key The key for the texture
@return The texture UIImage or nil
*/
- (UIImage *)imageForKey:(NSString *)key;
@end
@@ -1,132 +0,0 @@
// 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.
#import "FBSDKCameraEffectTextures.h"
#import "FBSDKCoreKit+Internal.h"
#import "FBSDKShareUtility.h"
static NSString *const FBSDKCameraEffectTexturesTexturesKey = @"textures";
@implementation FBSDKCameraEffectTextures
{
NSMutableDictionary<NSString *, UIImage *> *_textures;
}
#pragma mark - Object Lifecycle
- (instancetype)init
{
if ((self = [super init])) {
_textures = [NSMutableDictionary new];
}
return self;
}
- (void)setImage:(UIImage *)image forKey:(NSString *)key
{
[self _setValue:image forKey:key];
}
- (UIImage *)imageForKey:(NSString *)key
{
return [self _valueOfClass:[UIImage class] forKey:key];
}
- (NSDictionary<NSString *, UIImage *> *)allTextures
{
return _textures;
}
#pragma mark - Equality
- (NSUInteger)hash
{
return [_textures hash];
}
- (BOOL)isEqual:(id)object
{
if (self == object) {
return YES;
}
if (![object isKindOfClass:[FBSDKCameraEffectTextures class]]) {
return NO;
}
return [self isEqualToCameraEffectTextures:(FBSDKCameraEffectTextures *)object];
}
- (BOOL)isEqualToCameraEffectTextures:(FBSDKCameraEffectTextures *)object
{
return [FBSDKInternalUtility object:_textures isEqualToObject:[object allTextures]];
}
#pragma mark - NSCoding
+ (BOOL)supportsSecureCoding
{
return YES;
}
- (id)initWithCoder:(NSCoder *)decoder
{
if ((self = [self init])) {
_textures = [decoder decodeObjectOfClass:[NSMutableDictionary class]
forKey:FBSDKCameraEffectTexturesTexturesKey];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)encoder
{
[encoder encodeObject:_textures forKey:FBSDKCameraEffectTexturesTexturesKey];
}
#pragma mark - NSCopying
- (id)copyWithZone:(NSZone *)zone
{
FBSDKCameraEffectTextures *copy = [FBSDKCameraEffectTextures new];
copy->_textures = [_textures copy];
return copy;
}
#pragma mark - Helper Methods
- (void)_setValue:(id)value forKey:(NSString *)key
{
if (value) {
_textures[key] = value;
} else {
[_textures removeObjectForKey:key];
}
}
- (id)_valueForKey:(NSString *)key
{
key = [FBSDKTypeUtility stringValue:key];
return (key ? [FBSDKTypeUtility objectValue:_textures[key]] : nil);
}
- (id)_valueOfClass:(__unsafe_unretained Class)cls forKey:(NSString *)key
{
id value = [self _valueForKey:key];
return ([value isKindOfClass:cls] ? value : nil);
}
@end
@@ -1,140 +0,0 @@
// 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.
#import <Foundation/Foundation.h>
#import <FBSDKCoreKit/FBSDKCopying.h>
#import <FBSDKShareKit/FBSDKSharingValidation.h>
/**
NS_ENUM(NSUInteger, FBSDKGameRequestActionType)
Additional context about the nature of the request.
*/
typedef NS_ENUM(NSUInteger, FBSDKGameRequestActionType)
{
/** No action type */
FBSDKGameRequestActionTypeNone = 0,
/** Send action type: The user is sending an object to the friends. */
FBSDKGameRequestActionTypeSend,
/** Ask For action type: The user is asking for an object from friends. */
FBSDKGameRequestActionTypeAskFor,
/** Turn action type: It is the turn of the friends to play against the user in a match. (no object) */
FBSDKGameRequestActionTypeTurn,
};
/**
NS_ENUM(NSUInteger, FBSDKGameRequestFilters)
Filter for who can be displayed in the multi-friend selector.
*/
typedef NS_ENUM(NSUInteger, FBSDKGameRequestFilter)
{
/** No filter, all friends can be displayed. */
FBSDKGameRequestFilterNone = 0,
/** Friends using the app can be displayed. */
FBSDKGameRequestFilterAppUsers,
/** Friends not using the app can be displayed. */
FBSDKGameRequestFilterAppNonUsers,
};
/**
A model for a game request.
*/
@interface FBSDKGameRequestContent : NSObject <FBSDKCopying, FBSDKSharingValidation, NSSecureCoding>
/**
Used when defining additional context about the nature of the request.
The parameter 'objectID' is required if the action type is either
'FBSDKGameRequestSendActionType' or 'FBSDKGameRequestAskForActionType'.
- SeeAlso:objectID
*/
@property (nonatomic, assign) FBSDKGameRequestActionType actionType;
/**
Compares the receiver to another game request content.
@param content The other content
@return YES if the receiver's values are equal to the other content's values; otherwise NO
*/
- (BOOL)isEqualToGameRequestContent:(FBSDKGameRequestContent *)content;
/**
Additional freeform data you may pass for tracking. This will be stored as part of
the request objects created. The maximum length is 255 characters.
*/
@property (nonatomic, copy) NSString *data;
/**
This controls the set of friends someone sees if a multi-friend selector is shown.
It is FBSDKGameRequestNoFilter by default, meaning that all friends can be shown.
If specify as FBSDKGameRequestAppUsersFilter, only friends who use the app will be shown.
On the other hands, use FBSDKGameRequestAppNonUsersFilter to filter only friends who do not use the app.
The parameter name is preserved to be consistent with the counter part on desktop.
*/
@property (nonatomic, assign) FBSDKGameRequestFilter filters;
/**
A plain-text message to be sent as part of the request. This text will surface in the App Center view
of the request, but not on the notification jewel. Required parameter.
*/
@property (nonatomic, copy) NSString *message;
/**
The Open Graph object ID of the object being sent.
- SeeAlso:actionType
*/
@property (nonatomic, copy) NSString *objectID;
/**
An array of user IDs, usernames or invite tokens (NSString) of people to send request.
These may or may not be a friend of the sender. If this is specified by the app,
the sender will not have a choice of recipients. If not, the sender will see a multi-friend selector
This is equivalent to the "to" parameter when using the web game request dialog.
*/
@property (nonatomic, copy) NSArray *recipients;
/**
An array of user IDs that will be included in the dialog as the first suggested friends.
Cannot be used together with filters.
This is equivalent to the "suggestions" parameter when using the web game request dialog.
*/
@property (nonatomic, copy) NSArray *recipientSuggestions;
/**
@warning Use `recipientSuggestions` instead.
*/
@property (nonatomic, copy) NSArray *suggestions __attribute__ ((deprecated("use recipientSuggestions instead")));
/**
The title for the dialog.
*/
@property (nonatomic, copy) NSString *title;
/**
@warning Use `recipients` instead.
*/
@property (nonatomic, copy) NSArray *to __attribute__ ((deprecated("use recipients instead")));
@end
@@ -1,235 +0,0 @@
// 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.
#import "FBSDKGameRequestContent.h"
#import "FBSDKCoreKit+Internal.h"
#import "FBSDKShareError.h"
#import "FBSDKShareUtility.h"
#define FBSDK_APP_REQUEST_CONTENT_TO_KEY @"to"
#define FBSDK_APP_REQUEST_CONTENT_MESSAGE_KEY @"message"
#define FBSDK_APP_REQUEST_CONTENT_ACTION_TYPE_KEY @"actionType"
#define FBSDK_APP_REQUEST_CONTENT_OBJECT_ID_KEY @"objectID"
#define FBSDK_APP_REQUEST_CONTENT_FILTERS_KEY @"filters"
#define FBSDK_APP_REQUEST_CONTENT_SUGGESTIONS_KEY @"suggestions"
#define FBSDK_APP_REQUEST_CONTENT_DATA_KEY @"data"
#define FBSDK_APP_REQUEST_CONTENT_TITLE_KEY @"title"
@implementation FBSDKGameRequestContent
#pragma mark - Properties
-(void)setRecipients:(NSArray *)recipients
{
[FBSDKShareUtility assertCollection:recipients ofClass:[NSString class] name:@"recipients"];
if (![_recipients isEqual:recipients]) {
_recipients = [recipients copy];
}
}
- (void)setRecipientSuggestions:(NSArray *)recipientSuggestions
{
[FBSDKShareUtility assertCollection:recipientSuggestions ofClass:[NSString class] name:@"recipientSuggestions"];
if (![_recipientSuggestions isEqual:recipientSuggestions]) {
_recipientSuggestions = [recipientSuggestions copy];
}
}
- (NSArray *)suggestions
{
return self.recipientSuggestions;
}
- (void)setSuggestions:(NSArray *)suggestions
{
self.recipientSuggestions = suggestions;
}
- (NSArray *)to
{
return self.recipients;
}
- (void)setTo:(NSArray *)to
{
self.recipients = to;
}
#pragma mark - FBSDKSharingValidation
- (BOOL)validateWithOptions:(FBSDKShareBridgeOptions)bridgeOptions error:(NSError *__autoreleasing *)errorRef
{
if (![FBSDKShareUtility validateRequiredValue:_message name:@"message" error:errorRef]) {
return NO;
}
BOOL mustHaveobjectID = _actionType == FBSDKGameRequestActionTypeSend
|| _actionType == FBSDKGameRequestActionTypeAskFor;
BOOL hasobjectID = [_objectID length] > 0;
if (mustHaveobjectID ^ hasobjectID) {
if (errorRef != NULL) {
NSString *message = @"The objectID is required when the actionType is either send or askfor.";
*errorRef = [FBSDKShareError requiredArgumentErrorWithName:@"objectID" message:message];
}
return NO;
}
BOOL hasTo = [_recipients count] > 0;
BOOL hasFilters = _filters != FBSDKGameRequestFilterNone;
BOOL hasSuggestions = [_recipientSuggestions count] > 0;
if (hasTo && hasFilters) {
if (errorRef != NULL) {
NSString *message = @"Cannot specify to and filters at the same time.";
*errorRef = [FBSDKShareError invalidArgumentErrorWithName:@"recipients" value:_recipients message:message];
}
return NO;
}
if (hasTo && hasSuggestions) {
if (errorRef != NULL) {
NSString *message = @"Cannot specify to and suggestions at the same time.";
*errorRef = [FBSDKShareError invalidArgumentErrorWithName:@"recipients" value:_recipients message:message];
}
return NO;
}
if (hasFilters && hasSuggestions) {
if (errorRef != NULL) {
NSString *message = @"Cannot specify filters and suggestions at the same time.";
*errorRef = [FBSDKShareError invalidArgumentErrorWithName:@"recipientSuggestions" value:_recipientSuggestions message:message];
}
return NO;
}
if ([_data length] > 255) {
if (errorRef != NULL) {
NSString *message = @"The data cannot be longer than 255 characters";
*errorRef = [FBSDKShareError invalidArgumentErrorWithName:@"data" value:_data message:message];
}
return NO;
}
if (errorRef != NULL) {
*errorRef = nil;
}
return [FBSDKShareUtility validateArgumentWithName:@"actionType"
value:_actionType
isIn:@[@(FBSDKGameRequestActionTypeNone),
@(FBSDKGameRequestActionTypeSend),
@(FBSDKGameRequestActionTypeAskFor),
@(FBSDKGameRequestActionTypeTurn)]
error:errorRef]
&& [FBSDKShareUtility validateArgumentWithName:@"filters"
value:_filters
isIn:@[@(FBSDKGameRequestFilterNone),
@(FBSDKGameRequestFilterAppUsers),
@(FBSDKGameRequestFilterAppNonUsers)]
error:errorRef];
}
#pragma mark - Equality
- (NSUInteger)hash
{
NSUInteger subhashes[] = {
[FBSDKMath hashWithInteger:_actionType],
[_data hash],
[FBSDKMath hashWithInteger:_filters],
[_message hash],
[_objectID hash],
[_recipientSuggestions hash],
[_title hash],
[_recipients hash],
};
return [FBSDKMath hashWithIntegerArray:subhashes count:sizeof(subhashes) / sizeof(subhashes[0])];
}
- (BOOL)isEqual:(id)object
{
if (self == object) {
return YES;
}
if (![object isKindOfClass:[FBSDKGameRequestContent class]]) {
return NO;
}
return [self isEqualToGameRequestContent:(FBSDKGameRequestContent *)object];
}
- (BOOL)isEqualToGameRequestContent:(FBSDKGameRequestContent *)content
{
return (content &&
_actionType == content.actionType &&
_filters == content.filters &&
[FBSDKInternalUtility object:_data isEqualToObject:content.data] &&
[FBSDKInternalUtility object:_message isEqualToObject:content.message] &&
[FBSDKInternalUtility object:_objectID isEqualToObject:content.objectID] &&
[FBSDKInternalUtility object:_recipientSuggestions isEqualToObject:content.recipientSuggestions] &&
[FBSDKInternalUtility object:_title isEqualToObject:content.title] &&
[FBSDKInternalUtility object:_recipients isEqualToObject:content.recipients]);
}
#pragma mark - NSCoding
+ (BOOL)supportsSecureCoding
{
return YES;
}
- (id)initWithCoder:(NSCoder *)decoder
{
if ((self = [self init])) {
_actionType = [decoder decodeIntegerForKey:FBSDK_APP_REQUEST_CONTENT_ACTION_TYPE_KEY];
_data = [decoder decodeObjectOfClass:[NSString class] forKey:FBSDK_APP_REQUEST_CONTENT_DATA_KEY];
_filters = [decoder decodeIntegerForKey:FBSDK_APP_REQUEST_CONTENT_FILTERS_KEY];
_message = [decoder decodeObjectOfClass:[NSString class] forKey:FBSDK_APP_REQUEST_CONTENT_MESSAGE_KEY];
_objectID = [decoder decodeObjectOfClass:[NSString class] forKey:FBSDK_APP_REQUEST_CONTENT_OBJECT_ID_KEY];
_recipientSuggestions = [decoder decodeObjectOfClass:[NSArray class] forKey:FBSDK_APP_REQUEST_CONTENT_SUGGESTIONS_KEY];
_title = [decoder decodeObjectOfClass:[NSString class] forKey:FBSDK_APP_REQUEST_CONTENT_TITLE_KEY];
_recipients = [decoder decodeObjectOfClass:[NSArray class] forKey:FBSDK_APP_REQUEST_CONTENT_TO_KEY];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)encoder
{
[encoder encodeInteger:_actionType forKey:FBSDK_APP_REQUEST_CONTENT_ACTION_TYPE_KEY];
[encoder encodeObject:_data forKey:FBSDK_APP_REQUEST_CONTENT_DATA_KEY];
[encoder encodeInteger:_filters forKey:FBSDK_APP_REQUEST_CONTENT_FILTERS_KEY];
[encoder encodeObject:_message forKey:FBSDK_APP_REQUEST_CONTENT_MESSAGE_KEY];
[encoder encodeObject:_objectID forKey:FBSDK_APP_REQUEST_CONTENT_OBJECT_ID_KEY];
[encoder encodeObject:_recipientSuggestions forKey:FBSDK_APP_REQUEST_CONTENT_SUGGESTIONS_KEY];
[encoder encodeObject:_title forKey:FBSDK_APP_REQUEST_CONTENT_TITLE_KEY];
[encoder encodeObject:_recipients forKey:FBSDK_APP_REQUEST_CONTENT_TO_KEY];
}
#pragma mark - NSCopying
- (id)copyWithZone:(NSZone *)zone
{
FBSDKGameRequestContent *copy = [[FBSDKGameRequestContent alloc] init];
copy->_actionType = _actionType;
copy->_data = [_data copy];
copy->_filters = _filters;
copy->_message = [_message copy];
copy->_objectID = [_objectID copy];
copy->_recipientSuggestions = [_recipientSuggestions copy];
copy->_title = [_title copy];
copy->_recipients = [_recipients copy];
return copy;
}
@end
@@ -1,108 +0,0 @@
// 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.
#import <Foundation/Foundation.h>
#import <FBSDKShareKit/FBSDKGameRequestContent.h>
@protocol FBSDKGameRequestDialogDelegate;
/**
A dialog for sending game requests.
*/
@interface FBSDKGameRequestDialog : NSObject
/**
Convenience method to build up a game request with content and a delegate.
@param content The content for the game request.
@param delegate The receiver's delegate.
*/
+ (instancetype)showWithContent:(FBSDKGameRequestContent *)content delegate:(id<FBSDKGameRequestDialogDelegate>)delegate;
/**
The receiver's delegate or nil if it doesn't have a delegate.
*/
@property (nonatomic, weak) id<FBSDKGameRequestDialogDelegate> delegate;
/**
The content for game request.
*/
@property (nonatomic, copy) FBSDKGameRequestContent *content;
/**
Specifies whether frictionless requests are enabled.
*/
@property (nonatomic, assign) BOOL frictionlessRequestsEnabled;
/**
A Boolean value that indicates whether the receiver can initiate a game request.
May return NO if the appropriate Facebook app is not installed and is required or an access token is
required but not available. This method does not validate the content on the receiver, so this can be checked before
building up the content.
@see validateWithError:
@return YES if the receiver can share, otherwise NO.
*/
- (BOOL)canShow;
/**
Begins the game request from the receiver.
@return YES if the receiver was able to show the dialog, otherwise NO.
*/
- (BOOL)show;
/**
Validates the content on the receiver.
@param errorRef If an error occurs, upon return contains an NSError object that describes the problem.
@return YES if the content is valid, otherwise NO.
*/
- (BOOL)validateWithError:(NSError *__autoreleasing *)errorRef;
@end
/**
A delegate for FBSDKGameRequestDialog.
The delegate is notified with the results of the game request as long as the application has permissions to
receive the information. For example, if the person is not signed into the containing app, the shower may not be able
to distinguish between completion of a game request and cancellation.
*/
@protocol FBSDKGameRequestDialogDelegate <NSObject>
/**
Sent to the delegate when the game request completes without error.
@param gameRequestDialog The FBSDKGameRequestDialog that completed.
@param results The results from the dialog. This may be nil or empty.
*/
- (void)gameRequestDialog:(FBSDKGameRequestDialog *)gameRequestDialog didCompleteWithResults:(NSDictionary *)results;
/**
Sent to the delegate when the game request encounters an error.
@param gameRequestDialog The FBSDKGameRequestDialog that completed.
@param error The error.
*/
- (void)gameRequestDialog:(FBSDKGameRequestDialog *)gameRequestDialog didFailWithError:(NSError *)error;
/**
Sent to the delegate when the game request dialog is cancelled.
@param gameRequestDialog The FBSDKGameRequestDialog that completed.
*/
- (void)gameRequestDialogDidCancel:(FBSDKGameRequestDialog *)gameRequestDialog;
@end
@@ -1,274 +0,0 @@
// 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.
#import "FBSDKGameRequestDialog.h"
#import "FBSDKCoreKit+Internal.h"
#import "FBSDKGameRequestFrictionlessRecipientCache.h"
#import "FBSDKShareConstants.h"
#import "FBSDKShareError.h"
#import "FBSDKShareUtility.h"
@interface FBSDKGameRequestDialog () <FBSDKWebDialogDelegate>
@end
@implementation FBSDKGameRequestDialog
{
BOOL _dialogIsFrictionless;
FBSDKWebDialog *_webDialog;
}
#define FBSDK_APP_REQUEST_METHOD_NAME @"apprequests"
#pragma mark - Class Methods
static FBSDKGameRequestFrictionlessRecipientCache *_recipientCache = nil;
+ (void)initialize
{
if (self == [FBSDKGameRequestDialog class]) {
_recipientCache = [[FBSDKGameRequestFrictionlessRecipientCache alloc] init];
}
}
+ (instancetype)showWithContent:(FBSDKGameRequestContent *)content delegate:(id<FBSDKGameRequestDialogDelegate>)delegate
{
FBSDKGameRequestDialog *dialog = [[self alloc] init];
dialog.content = content;
dialog.delegate = delegate;
[dialog show];
return dialog;
}
#pragma mark - Object Lifecycle
- (instancetype)init
{
if ((self = [super init])) {
_webDialog = [[FBSDKWebDialog alloc] init];
_webDialog.delegate = self;
_webDialog.name = FBSDK_APP_REQUEST_METHOD_NAME;
}
return self;
}
- (void)dealloc
{
_webDialog.delegate = nil;
}
#pragma mark - Public Methods
- (BOOL)canShow
{
return YES;
}
- (BOOL)show
{
NSError *error;
if (![self canShow]) {
error = [FBSDKShareError errorWithCode:FBSDKShareDialogNotAvailableErrorCode
message:@"Game request dialog is not available."];
[_delegate gameRequestDialog:self didFailWithError:error];
return NO;
}
if (![self validateWithError:&error]) {
[_delegate gameRequestDialog:self didFailWithError:error];
return NO;
}
FBSDKGameRequestContent *content = self.content;
if (error) {
return NO;
}
NSMutableDictionary *parameters = [[NSMutableDictionary alloc] init];
[FBSDKInternalUtility dictionary:parameters setObject:[content.recipients componentsJoinedByString:@","] forKey:@"to"];
[FBSDKInternalUtility dictionary:parameters setObject:content.message forKey:@"message"];
[FBSDKInternalUtility dictionary:parameters setObject:[self _actionTypeNameForActionType:content.actionType] forKey:@"action_type"];
[FBSDKInternalUtility dictionary:parameters setObject:content.objectID forKey:@"object_id"];
[FBSDKInternalUtility dictionary:parameters setObject:[self _filtersNameForFilters:content.filters] forKey:@"filters"];
[FBSDKInternalUtility dictionary:parameters setObject:[content.recipientSuggestions componentsJoinedByString:@","] forKey:@"suggestions"];
[FBSDKInternalUtility dictionary:parameters setObject:content.data forKey:@"data"];
[FBSDKInternalUtility dictionary:parameters setObject:content.title forKey:@"title"];
// check if we are sending to a specific set of recipients. if we are and they are all frictionless recipients, we
// can perform this action without displaying the web dialog
_webDialog.deferVisibility = NO;
NSArray *recipients = content.recipients;
if (_frictionlessRequestsEnabled && recipients) {
// specify these parameters to get the frictionless recipients from the dialog when it is presented
parameters[@"frictionless"] = @YES;
parameters[@"get_frictionless_recipients"] = @YES;
_dialogIsFrictionless = YES;
if ([_recipientCache recipientsAreFrictionless:recipients]) {
_webDialog.deferVisibility = YES;
}
}
_webDialog.parameters = parameters;
[_webDialog show];
[FBSDKInternalUtility registerTransientObject:self];
return YES;
}
- (BOOL)validateWithError:(NSError *__autoreleasing *)errorRef
{
if (![FBSDKShareUtility validateRequiredValue:self.content name:@"content" error:errorRef]) {
return NO;
}
if ([self.content respondsToSelector:@selector(validateWithOptions:error:)]) {
return [self.content validateWithOptions:FBSDKShareBridgeOptionsDefault error:errorRef];
}
if (errorRef != NULL) {
*errorRef = [FBSDKShareError invalidArgumentErrorWithName:@"content" value:self.content message:nil];
}
return NO;
}
#pragma mark - FBSDKWebDialogDelegate
- (void)webDialog:(FBSDKWebDialog *)webDialog didCompleteWithResults:(NSDictionary *)results
{
if (_webDialog != webDialog) {
return;
}
if (_dialogIsFrictionless && results) {
[_recipientCache updateWithResults:results];
}
[self _cleanUp];
NSError *error = [FBSDKShareError errorWithCode:[FBSDKTypeUtility unsignedIntegerValue:results[@"error_code"]]
message:[FBSDKTypeUtility stringValue:results[@"error_message"]]];
if (!error.code) {
// reformat "to[x]" keys into an array.
int counter = 0;
NSMutableArray *toArray = [NSMutableArray array];
while (true) {
NSString *key = [NSString stringWithFormat:@"to[%d]", counter++];
if (results[key]) {
[toArray addObject:results[key]];
} else {
break;
}
}
if (toArray.count) {
NSMutableDictionary *mutableResults = [results mutableCopy];
mutableResults[@"to"] = toArray;
results = mutableResults;
}
}
[self _handleCompletionWithDialogResults:results error:error];
[FBSDKInternalUtility unregisterTransientObject:self];
}
- (void)webDialog:(FBSDKWebDialog *)webDialog didFailWithError:(NSError *)error
{
if (_webDialog != webDialog) {
return;
}
[self _cleanUp];
[self _handleCompletionWithDialogResults:nil error:error];
[FBSDKInternalUtility unregisterTransientObject:self];
}
- (void)webDialogDidCancel:(FBSDKWebDialog *)webDialog
{
if (_webDialog != webDialog) {
return;
}
[self _cleanUp];
[_delegate gameRequestDialogDidCancel:self];
[FBSDKInternalUtility unregisterTransientObject:self];
}
#pragma mark - Helper Methods
- (void)_cleanUp
{
_dialogIsFrictionless = NO;
}
- (void)_handleCompletionWithDialogResults:(NSDictionary *)results error:(NSError *)error
{
if (!_delegate) {
return;
}
switch (error.code) {
case 0:{
[_delegate gameRequestDialog:self didCompleteWithResults:results];
break;
}
case 4201:{
[_delegate gameRequestDialogDidCancel:self];
break;
}
default:{
[_delegate gameRequestDialog:self didFailWithError:error];
break;
}
}
if (error) {
return;
} else {
}
}
- (NSString *)_actionTypeNameForActionType:(FBSDKGameRequestActionType)actionType
{
switch (actionType) {
case FBSDKGameRequestActionTypeNone:{
return nil;
}
case FBSDKGameRequestActionTypeSend:{
return @"send";
}
case FBSDKGameRequestActionTypeAskFor:{
return @"askfor";
}
case FBSDKGameRequestActionTypeTurn:{
return @"turn";
}
default:{
return nil;
}
}
}
- (NSString *)_filtersNameForFilters:(FBSDKGameRequestFilter)filters
{
switch (filters) {
case FBSDKGameRequestFilterNone:{
return nil;
}
case FBSDKGameRequestFilterAppUsers:{
return @"app_users";
}
case FBSDKGameRequestFilterAppNonUsers:{
return @"app_non_users";
}
default:{
return nil;
}
}
}
@end
@@ -1,61 +0,0 @@
// 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.
#import <Foundation/Foundation.h>
#import <FBSDKCoreKit/FBSDKCopying.h>
/**
Represents a single hashtag that can be used with the share dialog.
*/
@interface FBSDKHashtag : NSObject <FBSDKCopying, NSSecureCoding>
/**
Convenience method to build a new hashtag with a string identifier. Equivalent to setting the
`stringRepresentation` property.
@param hashtagString The hashtag string.
*/
+ (instancetype)hashtagWithString:(NSString *)hashtagString;
/**
The hashtag string.
You are responsible for making sure that `stringRepresentation` is a valid hashtag (a single '#' followed
by one or more word characters). Invalid hashtags are ignored when sharing content. You can check validity with the
`valid` property.
@return The hashtag string.
*/
@property (nonatomic, readwrite, copy) NSString *stringRepresentation;
/**
Tests if a hashtag is valid.
A valid hashtag matches the regular expression "#\w+": A single '#' followed by one or more
word characters.
@return YES if the hashtag is valid, NO otherwise.
*/
@property (nonatomic, readonly, assign, getter=isValid) BOOL valid;
/**
Compares the receiver to another hashtag.
@param hashtag The other hashtag
@return YES if the receiver is equal to the other hashtag; otherwise NO
*/
- (BOOL)isEqualToHashtag:(FBSDKHashtag *)hashtag;
@end
@@ -1,123 +0,0 @@
// 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.
#import "FBSDKHashtag.h"
#import "FBSDKCoreKit+Internal.h"
#define FBSDK_HASHTAG_STRING_KEY @"hashtag"
static NSRegularExpression *HashtagRegularExpression()
{
static NSRegularExpression *hashtagRegularExpression = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
hashtagRegularExpression = [[NSRegularExpression alloc] initWithPattern:@"^#\\w+$" options:0 error:NULL];
});
return hashtagRegularExpression;
}
@implementation FBSDKHashtag
#pragma mark - Class Methods
+ (instancetype)hashtagWithString:(NSString *)hashtagString
{
FBSDKHashtag *hashtag = [[self alloc] init];
hashtag.stringRepresentation = hashtagString;
return hashtag;
}
#pragma mark - Properties
- (NSString *)description
{
if (self.valid) {
return _stringRepresentation;
} else {
return [NSString stringWithFormat:@"Invalid hashtag '%@'", _stringRepresentation];
}
}
- (BOOL)isValid
{
if (_stringRepresentation == nil) {
return NO;
}
NSRange fullString = NSMakeRange(0, _stringRepresentation.length);
NSRegularExpression *hashtagRegularExpression = HashtagRegularExpression();
NSUInteger numberOfMatches = [hashtagRegularExpression numberOfMatchesInString:_stringRepresentation
options:0
range:fullString];
return numberOfMatches > 0;
}
#pragma mark - Equality
- (NSUInteger)hash
{
return [_stringRepresentation hash];
}
- (BOOL)isEqual:(id)object
{
if (self == object) {
return YES;
}
if (![object isKindOfClass:[FBSDKHashtag class]]) {
return NO;
}
return [self isEqualToHashtag:(FBSDKHashtag *)object];
}
- (BOOL)isEqualToHashtag:(FBSDKHashtag *)hashtag
{
return (hashtag &&
[FBSDKInternalUtility object:_stringRepresentation isEqualToObject:hashtag.stringRepresentation]);
}
#pragma mark - NSCoding
+ (BOOL)supportsSecureCoding
{
return YES;
}
- (id)initWithCoder:(NSCoder *)aDecoder
{
if ((self = [self init])) {
_stringRepresentation = [aDecoder decodeObjectOfClass:[NSString class] forKey:FBSDK_HASHTAG_STRING_KEY];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)aCoder
{
[aCoder encodeObject:_stringRepresentation forKey:FBSDK_HASHTAG_STRING_KEY];
}
#pragma mark - NSCopying
- (id)copyWithZone:(NSZone *)zone
{
FBSDKHashtag *copy = [[FBSDKHashtag alloc] init];
copy.stringRepresentation = [_stringRepresentation copy];
return copy;
}
@end
@@ -1,45 +0,0 @@
// 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.
#import <UIKit/UIKit.h>
#import <FBSDKCoreKit/FBSDKButton.h>
#import <FBSDKShareKit/FBSDKLikeObjectType.h>
#import <FBSDKShareKit/FBSDKLiking.h>
/**
Warning: This class is deprecated.
A button to like an object.
Tapping the receiver will invoke an API call to the Facebook app through a fast-app-switch that allows
the object to be liked. Upon return to the calling app, the view will update with the new state. If the
currentAccessToken has "publish_actions" permission and the object is an Open Graph object, then the like can happen
seamlessly without the fast-app-switch.
*/
__attribute__ ((deprecated))
@interface FBSDKLikeButton : FBSDKButton <FBSDKLiking>
/**
If YES, a sound is played when the receiver is toggled.
@default YES
*/
@property (nonatomic, assign, getter = isSoundEnabled) BOOL soundEnabled;
@end
@@ -1,294 +0,0 @@
// 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.
#import "FBSDKLikeButton.h"
#import "FBSDKLikeButton+Internal.h"
#import "FBSDKCheckmarkIcon.h"
#import "FBSDKCoreKit+Internal.h"
#import "FBSDKLikeActionController.h"
#import "FBSDKLikeControl+Internal.h"
#define FBSDK_LIKE_BUTTON_ANIMATION_DURATION 0.2
#define FBSDK_LIKE_BUTTON_ANIMATION_SPRING_DAMPING 0.3
#define FBSDK_LIKE_BUTTON_ANIMATION_SPRING_VELOCITY 0.2
@implementation FBSDKLikeButton
{
BOOL _isExplicitlyDisabled;
FBSDKLikeActionController *_likeActionController;
NSString *_objectID;
FBSDKLikeObjectType _objectType;
}
#pragma mark - Class Methods
+ (void)initialize
{
if ([FBSDKLikeButton class] == self) {
// ensure that we have updated the dialog configs if we haven't already
[FBSDKServerConfigurationManager loadServerConfigurationWithCompletionBlock:NULL];
}
}
#pragma mark - Object Lifecycle
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
[_likeActionController endContentAccess];
}
#pragma mark - Properties
- (FBSDKLikeActionController *)likeActionController
{
[self _ensureLikeActionController:NO];
return _likeActionController;
}
- (void)setLikeActionController:(FBSDKLikeActionController *)likeActionController
{
[self _setLikeActionController:likeActionController];
}
- (NSString *)objectID
{
return _objectID;
}
- (void)setObjectID:(NSString *)objectID
{
if (![_objectID isEqualToString:objectID]) {
_objectID = objectID;
[self checkImplicitlyDisabled];
[self _resetLikeActionController];
}
}
- (FBSDKLikeObjectType)objectType
{
return _objectType;
}
- (void)setObjectType:(FBSDKLikeObjectType)objectType
{
if (_objectType != objectType) {
_objectType = objectType;
[self _resetLikeActionController];
}
}
#pragma mark - Layout
- (void)layoutSubviews
{
[self _ensureLikeActionController:YES];
[super layoutSubviews];
}
#pragma mark - FBSDKButtonImpressionTracking
- (NSDictionary *)analyticsParameters
{
UIView *superview = self.superview;
while (superview && ![superview isKindOfClass:[FBSDKLikeControl class]]) {
superview = superview.superview;
}
if ([superview isKindOfClass:[FBSDKLikeControl class]]) {
return ((FBSDKLikeControl *)superview).analyticsParameters;
}
return @{
@"object_id": (self.objectID ?: [NSNull null]),
@"object_type": (NSStringFromFBSDKLikeObjectType(self.objectType) ?: [NSNull null]),
@"sound_enabled": @(self.soundEnabled),
};
}
- (NSString *)impressionTrackingEventName
{
return FBSDKAppEventNameFBSDKLikeButtonImpression;
}
- (NSString *)impressionTrackingIdentifier
{
return self.objectID;
}
#pragma mark - FBSDKButton
- (void)configureButton
{
self.soundEnabled = YES;
NSString *title =
NSLocalizedStringWithDefaultValue(@"LikeButton.Like", @"FacebookSDK", [FBSDKInternalUtility bundleForStrings],
@"Like",
@"The label for the FBSDKLikeButton when the object is not currently liked.");
NSString *selectedTitle =
NSLocalizedStringWithDefaultValue(@"LikeButton.Liked", @"FacebookSDK", [FBSDKInternalUtility bundleForStrings],
@"Liked",
@"The label for the FBSDKLikeButton when the object is currently liked.");
UIColor *backgroundColor = [self defaultBackgroundColor];
UIColor *highlightedColor = [self defaultHighlightedColor];
UIColor *selectedColor = [self defaultSelectedColor];
UIColor *selectedHighlightedColor = [UIColor colorWithRed:99.0/255.0 green:119.0/255.0 blue:178.0/255.0 alpha:1.0];
[self configureWithIcon:nil
title:title
backgroundColor:backgroundColor
highlightedColor:highlightedColor
selectedTitle:selectedTitle
selectedIcon:[[FBSDKCheckmarkIcon alloc] init]
selectedColor:selectedColor
selectedHighlightedColor:selectedHighlightedColor];
[self addTarget:self action:@selector(_handleTap:) forControlEvents:UIControlEventTouchUpInside];
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self
selector:@selector(_likeActionControllerDidDisableNotification:)
name:FBSDKLikeActionControllerDidDisableNotification
object:nil];
[nc addObserver:self
selector:@selector(_likeActionControllerDidResetNotification:)
name:FBSDKLikeActionControllerDidResetNotification
object:nil];
[nc addObserver:self
selector:@selector(_likeActionControllerDidUpdateNotification:)
name:FBSDKLikeActionControllerDidUpdateNotification
object:nil];
}
- (BOOL)isImplicitlyDisabled
{
return !self.objectID || [FBSDKLikeActionController isDisabled];
}
#pragma mark - Helper Methods
- (void)_ensureLikeActionController:(BOOL)notifyKVO
{
if (!_likeActionController) {
FBSDKLikeActionController *likeActionController = [FBSDKLikeActionController likeActionControllerForObjectID:_objectID
objectType:_objectType];
if (notifyKVO) {
self.likeActionController = likeActionController;
} else {
[self _setLikeActionController:likeActionController];
}
[likeActionController endContentAccess];
self.selected = _likeActionController.objectIsLiked;
}
}
- (void)_handleTap:(FBSDKLikeButton *)likeButton
{
[self logTapEventWithEventName:FBSDKAppEventNameFBSDKLikeButtonDidTap parameters:[self analyticsParameters]];
[self _ensureLikeActionController:YES];
[_likeActionController toggleLikeWithSoundEnabled:self.soundEnabled
analyticsParameters:[self analyticsParameters]
fromViewController:[FBSDKInternalUtility viewControllerForView:self]];
}
- (void)_like:(id)sender
{
[_likeActionController toggleLikeWithSoundEnabled:_soundEnabled
analyticsParameters:[self analyticsParameters]
fromViewController:[FBSDKInternalUtility viewControllerForView:self]];
}
- (void)_likeActionControllerDidDisableNotification:(NSNotification *)notification
{
[self checkImplicitlyDisabled];
}
- (void)_likeActionControllerDidResetNotification:(NSNotification *)notification
{
[self _resetLikeActionController];
[self _ensureLikeActionController:YES];
}
- (void)_likeActionControllerDidUpdateNotification:(NSNotification *)notification
{
[self _ensureLikeActionController:YES];
FBSDKLikeActionController *likeActionController = (FBSDKLikeActionController *)notification.object;
NSString *objectID = likeActionController.objectID;
if ([self.objectID isEqualToString:objectID]) {
BOOL animated = [notification.userInfo[FBSDKLikeActionControllerAnimatedKey] boolValue];
[self _setSelected:likeActionController.objectIsLiked animated:animated];
}
}
- (void)_resetLikeActionController
{
self.likeActionController = nil;
[self setNeedsLayout];
}
- (void)_setLikeActionController:(FBSDKLikeActionController *)likeActionController
{
if (_likeActionController != likeActionController) {
[_likeActionController endContentAccess];
_likeActionController = likeActionController;
[_likeActionController beginContentAccess];
}
}
- (void)_setSelected:(BOOL)selected animated:(BOOL)animated
{
if (self.selected != selected) {
if (animated) {
CFTimeInterval duration = FBSDK_LIKE_BUTTON_ANIMATION_DURATION;
UIViewAnimationOptions options = UIViewAnimationOptionBeginFromCurrentState;
UIImageView *imageView = self.imageView;
imageView.frame = [self imageRectForContentRect:UIEdgeInsetsInsetRect(self.bounds, self.contentEdgeInsets)];
[UIView animateWithDuration:duration delay:0.0 options:options animations:^{
CGPoint iconImageViewCenter = imageView.center;
imageView.frame = CGRectMake(iconImageViewCenter.x, iconImageViewCenter.y, 0.0, 0.0);
} completion:^(BOOL animateOutFinished) {
self.selected = selected;
CGPoint iconImageViewCenter = imageView.center;
imageView.frame = CGRectMake(iconImageViewCenter.x, iconImageViewCenter.y, 0.0, 0.0);
void(^animations)(void) = ^{
imageView.frame = [self imageRectForContentRect:UIEdgeInsetsInsetRect(self.bounds, self.contentEdgeInsets)];
};
if ([UIView respondsToSelector:@selector(animateWithDuration:delay:usingSpringWithDamping:initialSpringVelocity:options:animations:completion:)]) {
[UIView animateWithDuration:(duration * 2)
delay:0.0
usingSpringWithDamping:FBSDK_LIKE_BUTTON_ANIMATION_SPRING_DAMPING
initialSpringVelocity:FBSDK_LIKE_BUTTON_ANIMATION_SPRING_VELOCITY
options:options
animations:animations
completion:NULL];
} else {
[UIView animateWithDuration:(duration * 2)
delay:0.0
options:options
animations:animations
completion:NULL];
}
}];
} else {
self.selected = selected;
}
}
}
@end
@@ -1,144 +0,0 @@
// 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.
#import <UIKit/UIKit.h>
#import <FBSDKCoreKit/FBSDKMacros.h>
#import <FBSDKShareKit/FBSDKLikeObjectType.h>
#import <FBSDKShareKit/FBSDKLiking.h>
/**
NS_ENUM (NSUInteger, FBSDKLikeControlAuxiliaryPosition)
Specifies the position of the auxiliary view relative to the like button.
*/
typedef NS_ENUM(NSUInteger, FBSDKLikeControlAuxiliaryPosition)
{
/** The auxiliary view is inline with the like button. */
FBSDKLikeControlAuxiliaryPositionInline,
/** The auxiliary view is above the like button. */
FBSDKLikeControlAuxiliaryPositionTop,
/** The auxiliary view is below the like button. */
FBSDKLikeControlAuxiliaryPositionBottom,
};
/**
Converts an FBSDKLikeControlAuxiliaryPosition to an NSString.
*/
FBSDK_EXTERN NSString *NSStringFromFBSDKLikeControlAuxiliaryPosition(FBSDKLikeControlAuxiliaryPosition auxiliaryPosition);
/**
NS_ENUM(NSUInteger, FBSDKLikeControlHorizontalAlignment)
Specifies the horizontal alignment for FBSDKLikeControlStyleStandard with
FBSDKLikeControlAuxiliaryPositionTop or FBSDKLikeControlAuxiliaryPositionBottom.
*/
typedef NS_ENUM(NSUInteger, FBSDKLikeControlHorizontalAlignment)
{
/** The subviews are left aligned. */
FBSDKLikeControlHorizontalAlignmentLeft,
/** The subviews are center aligned. */
FBSDKLikeControlHorizontalAlignmentCenter,
/** The subviews are right aligned. */
FBSDKLikeControlHorizontalAlignmentRight,
};
/**
Converts an FBSDKLikeControlHorizontalAlignment to an NSString.
*/
FBSDK_EXTERN NSString *NSStringFromFBSDKLikeControlHorizontalAlignment(FBSDKLikeControlHorizontalAlignment horizontalAlignment);
/**
NS_ENUM (NSUInteger, FBSDKLikeControlStyle)
Specifies the style of a like control.
*/
typedef NS_ENUM(NSUInteger, FBSDKLikeControlStyle)
{
/** Displays the button and the social sentence. */
FBSDKLikeControlStyleStandard = 0,
/** Displays the button and a box that contains the like count. */
FBSDKLikeControlStyleBoxCount,
};
/**
Converts an FBSDKLikeControlStyle to an NSString.
*/
FBSDK_EXTERN NSString *NSStringFromFBSDKLikeControlStyle(FBSDKLikeControlStyle style);
/**
Warning: This class is deprecated.
UI control to like an object in the Facebook graph.
Taps on the like button within this control will invoke an API call to the Facebook app through a
fast-app-switch that allows the user to like the object. Upon return to the calling app, the view will update
with the new state and send actions for the UIControlEventValueChanged event.
*/
__attribute__ ((deprecated))
@interface FBSDKLikeControl : UIControl <FBSDKLiking>
/**
The foreground color to use for the content of the receiver.
*/
@property (nonatomic, strong) UIColor *foregroundColor;
/**
The position for the auxiliary view for the receiver.
@see FBSDKLikeControlAuxiliaryPosition
*/
@property (nonatomic, assign) FBSDKLikeControlAuxiliaryPosition likeControlAuxiliaryPosition;
/**
The text alignment of the social sentence.
This value is only valid for FBSDKLikeControlStyleStandard with
FBSDKLikeControlAuxiliaryPositionTop|Bottom.
*/
@property (nonatomic, assign) FBSDKLikeControlHorizontalAlignment likeControlHorizontalAlignment;
/**
The style to use for the receiver.
@see FBSDKLikeControlStyle
*/
@property (nonatomic, assign) FBSDKLikeControlStyle likeControlStyle;
/**
The preferred maximum width (in points) for autolayout.
This property affects the size of the receiver when layout constraints are applied to it. During layout,
if the text extends beyond the width specified by this property, the additional text is flowed to one or more new
lines, thereby increasing the height of the receiver.
*/
@property (nonatomic, assign) CGFloat preferredMaxLayoutWidth;
/**
If YES, a sound is played when the receiver is toggled.
@default YES
*/
@property (nonatomic, assign, getter = isSoundEnabled) BOOL soundEnabled;
@end
@@ -1,664 +0,0 @@
// 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.
#import "FBSDKLikeControl.h"
#import "FBSDKLikeControl+Internal.h"
#import "FBSDKCoreKit+Internal.h"
#import "FBSDKLikeActionController.h"
#import "FBSDKLikeBoxView.h"
#import "FBSDKLikeButton+Internal.h"
#import "FBSDKLikeButton.h"
#define kFBLikeControlAnimationDuration 0.2
#define kFBLikeControlSocialSentenceAnimationOffset 10.0
static void *FBSDKLikeControlKVOLikeActionControllerContext = &FBSDKLikeControlKVOLikeActionControllerContext;
NSString *NSStringFromFBSDKLikeControlAuxiliaryPosition(FBSDKLikeControlAuxiliaryPosition auxiliaryPosition)
{
switch (auxiliaryPosition) {
case FBSDKLikeControlAuxiliaryPositionBottom:
return @"bottom";
case FBSDKLikeControlAuxiliaryPositionInline:
return @"inline";
case FBSDKLikeControlAuxiliaryPositionTop:
return @"top";
}
return nil;
}
NSString *NSStringFromFBSDKLikeControlHorizontalAlignment(FBSDKLikeControlHorizontalAlignment horizontalAlignment)
{
switch (horizontalAlignment) {
case FBSDKLikeControlHorizontalAlignmentCenter:
return @"center";
case FBSDKLikeControlHorizontalAlignmentLeft:
return @"left";
case FBSDKLikeControlHorizontalAlignmentRight:
return @"right";
}
return nil;
}
NSString *NSStringFromFBSDKLikeControlStyle(FBSDKLikeControlStyle style)
{
switch (style) {
case FBSDKLikeControlStyleBoxCount:
return @"box_count";
case FBSDKLikeControlStyleStandard:
return @"standard";
}
return nil;
}
typedef struct FBSDKLikeControlLayout
{
CGSize contentSize;
CGRect likeButtonFrame;
CGRect auxiliaryViewFrame;
} FBSDKLikeControlLayout;
typedef CGSize (^fbsdk_like_control_sizing_block_t)(UIView *subview, CGSize constrainedSize);
@implementation FBSDKLikeControl
{
BOOL _isExplicitlyDisabled;
FBSDKLikeBoxView *_likeBoxView;
FBSDKLikeButton *_likeButton;
UIView *_likeButtonContainer;
UILabel *_socialSentenceLabel;
}
#pragma mark - Class Methods
+ (void)initialize
{
if ([FBSDKLikeControl class] == self) {
// ensure that we have updated the dialog configs if we haven't already
[FBSDKServerConfigurationManager loadServerConfigurationWithCompletionBlock:NULL];
}
}
#pragma mark - Object Lifecycle
- (instancetype)initWithFrame:(CGRect)frame
{
if ((self = [super initWithFrame:frame])) {
[self _initializeContent];
if (CGRectEqualToRect(frame, CGRectZero)) {
[self sizeToFit];
}
}
return self;
}
- (id)initWithCoder:(NSCoder *)decoder
{
if ((self = [super initWithCoder:decoder])) {
[self _initializeContent];
}
return self;
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
[_likeButton removeObserver:self forKeyPath:@"likeActionController"];
}
#pragma mark - Properties
- (void)setBackgroundColor:(UIColor *)backgroundColor
{
[super setBackgroundColor:backgroundColor];
_likeButtonContainer.backgroundColor = backgroundColor;
}
- (void)setForegroundColor:(UIColor *)foregroundColor
{
if (![_foregroundColor isEqual:foregroundColor]) {
_foregroundColor = foregroundColor;
[_likeButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
_socialSentenceLabel.textColor = foregroundColor;
}
}
- (void)setEnabled:(BOOL)enabled
{
_isExplicitlyDisabled = !enabled;
[self _updateEnabled];
}
- (void)setLikeControlAuxiliaryPosition:(FBSDKLikeControlAuxiliaryPosition)likeControlAuxiliaryPosition
{
if (_likeControlAuxiliaryPosition != likeControlAuxiliaryPosition) {
_likeControlAuxiliaryPosition = likeControlAuxiliaryPosition;
[self _updateLikeBoxCaretPosition];
[self setNeedsLayout];
[self setNeedsUpdateConstraints];
[self invalidateIntrinsicContentSize];
}
}
- (void)setLikeControlHorizontalAlignment:(FBSDKLikeControlHorizontalAlignment)likeControlHorizontalAlignment
{
if (_likeControlHorizontalAlignment != likeControlHorizontalAlignment) {
_likeControlHorizontalAlignment = likeControlHorizontalAlignment;
[self _updateLikeBoxCaretPosition];
[self setNeedsLayout];
[self setNeedsUpdateConstraints];
[self invalidateIntrinsicContentSize];
}
}
- (void)setLikeControlStyle:(FBSDKLikeControlStyle)likeControlStyle
{
if (_likeControlStyle != likeControlStyle) {
_likeControlStyle = likeControlStyle;
[self _updateLikeBoxCaretPosition];
[self setNeedsLayout];
[self setNeedsUpdateConstraints];
[self invalidateIntrinsicContentSize];
}
}
- (NSString *)objectID
{
return _likeButton.objectID;
}
- (void)setObjectID:(NSString *)objectID
{
if (![_likeButton.objectID isEqualToString:objectID]) {
_likeButton.objectID = objectID;
[self _updateEnabled];
[self setNeedsLayout];
}
}
- (FBSDKLikeObjectType)objectType
{
return _likeButton.objectType;
}
- (void)setObjectType:(FBSDKLikeObjectType)objectType
{
if (_likeButton.objectType != objectType) {
_likeButton.objectType = objectType;
[self setNeedsLayout];
}
}
- (void)setOpaque:(BOOL)opaque
{
[super setOpaque:opaque];
_likeButtonContainer.opaque = opaque;
}
- (BOOL)isSoundEnabled
{
return _likeButton.soundEnabled;
}
- (void)setSoundEnabled:(BOOL)soundEnabled
{
_likeButton.soundEnabled = soundEnabled;
}
#pragma mark - Layout
- (CGSize)intrinsicContentSize
{
CGFloat width = self.preferredMaxLayoutWidth;
if (width == 0) {
width = CGFLOAT_MAX;
}
CGRect bounds = CGRectMake(0.0, 0.0, width, CGFLOAT_MAX);
return [self _layoutWithBounds:bounds subviewSizingBlock:^CGSize(UIView *subview, CGSize constrainedSize) {
if ([subview respondsToSelector:@selector(setPreferredMaxLayoutWidth:)]) {
[(id)subview setPreferredMaxLayoutWidth:constrainedSize.width];
}
return subview.intrinsicContentSize;
}].contentSize;
}
- (void)layoutSubviews
{
[super layoutSubviews];
NSString *objectID = self.objectID;
if (objectID) {
FBSDKViewImpressionTracker *impressionTracker =
[FBSDKViewImpressionTracker impressionTrackerWithEventName:FBSDKAppEventNameFBSDKLikeControlImpression];
[impressionTracker logImpressionWithIdentifier:objectID parameters:[self analyticsParameters]];
}
[self _ensureLikeActionController];
CGRect bounds = self.bounds;
CGSize(^sizingBlock)(UIView *, CGSize) = ^CGSize(UIView *subview, CGSize constrainedSize) {
return [subview sizeThatFits:constrainedSize];
};
FBSDKLikeControlLayout layout = [self _layoutWithBounds:bounds subviewSizingBlock:sizingBlock];
UIView *auxiliaryView = [self _auxiliaryView];
_likeBoxView.hidden = (_likeBoxView != auxiliaryView);
_socialSentenceLabel.hidden = (_socialSentenceLabel != auxiliaryView);
_likeButtonContainer.frame = layout.likeButtonFrame;
_likeButton.frame = _likeButtonContainer.bounds;
auxiliaryView.frame = layout.auxiliaryViewFrame;
}
- (CGSize)sizeThatFits:(CGSize)size
{
switch (self.likeControlAuxiliaryPosition) {
case FBSDKLikeControlAuxiliaryPositionInline:{
size.height = MAX(size.height, CGRectGetHeight(self.bounds));
break;
}
case FBSDKLikeControlAuxiliaryPositionTop:
case FBSDKLikeControlAuxiliaryPositionBottom:{
size.width = MAX(size.width, CGRectGetWidth(self.bounds));
break;
}
}
CGRect bounds = CGRectMake(0.0, 0.0, size.width, size.height);
return [self _layoutWithBounds:bounds subviewSizingBlock:^CGSize(UIView *subview, CGSize constrainedSize) {
return [subview sizeThatFits:constrainedSize];
}].contentSize;
}
#pragma mark - Internal Methods
- (NSDictionary *)analyticsParameters
{
return @{
@"auxiliary_position": NSStringFromFBSDKLikeControlAuxiliaryPosition(self.likeControlAuxiliaryPosition),
@"horizontal_alignment": NSStringFromFBSDKLikeControlHorizontalAlignment(self.likeControlHorizontalAlignment),
@"object_id": (self.objectID ?: [NSNull null]),
@"object_type": (NSStringFromFBSDKLikeObjectType(self.objectType) ?: [NSNull null]),
@"sound_enabled": @(self.soundEnabled),
@"style": NSStringFromFBSDKLikeControlStyle(self.likeControlStyle),
};
}
#pragma mark - Helper Methods
- (UIView *)_auxiliaryView
{
[self _ensureLikeActionController];
switch (_likeControlStyle) {
case FBSDKLikeControlStyleStandard:{
return (_socialSentenceLabel.text.length == 0 ? nil : _socialSentenceLabel);
}
case FBSDKLikeControlStyleBoxCount:{
return (_likeButton.likeActionController.likeCountString == nil ? nil : _likeBoxView);
}
}
return nil;
}
- (CGFloat)_auxiliaryViewPadding
{
switch (_likeControlStyle) {
case FBSDKLikeControlStyleStandard:{
return 8.0;
}
case FBSDKLikeControlStyleBoxCount:{
return 0.0;
}
}
return 0.0;
}
- (void)_ensureLikeActionController
{
FBSDKLikeActionController *likeActionController = _likeButton.likeActionController;
if (likeActionController) {
_socialSentenceLabel.text = likeActionController.socialSentence;
_likeBoxView.text = likeActionController.likeCountString;
}
}
- (void)_handleLikeButtonTap:(FBSDKLikeButton *)likeButton
{
[self _ensureLikeActionController];
[self sendActionsForControlEvents:UIControlEventTouchUpInside];
}
- (void)_initializeContent
{
self.backgroundColor = [UIColor clearColor];
_foregroundColor = [UIColor blackColor];
_likeButtonContainer = [[UIView alloc] initWithFrame:CGRectZero];
_likeButtonContainer.backgroundColor = self.backgroundColor;
_likeButtonContainer.opaque = self.opaque;
[self addSubview:_likeButtonContainer];
_likeButton = [[FBSDKLikeButton alloc] initWithFrame:CGRectZero];
[_likeButton addTarget:self action:@selector(_handleLikeButtonTap:) forControlEvents:UIControlEventTouchUpInside];
[_likeButtonContainer addSubview:_likeButton];
_socialSentenceLabel = [[UILabel alloc] initWithFrame:CGRectZero];
_socialSentenceLabel.font = [UIFont systemFontOfSize:11.0];
_socialSentenceLabel.numberOfLines = 2;
[self addSubview:_socialSentenceLabel];
_likeBoxView = [[FBSDKLikeBoxView alloc] initWithFrame:CGRectZero];
[self addSubview:_likeBoxView];
// use KVO to monitor changes to the likeActionController instance on FBSDKButton in order to avoid race conditions
// between notification observers
[_likeButton addObserver:self
forKeyPath:@"likeActionController"
options:NSKeyValueObservingOptionInitial
context:FBSDKLikeControlKVOLikeActionControllerContext];
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self
selector:@selector(_likeActionControllerDidDisableNotification:)
name:FBSDKLikeActionControllerDidDisableNotification
object:nil];
[nc addObserver:self
selector:@selector(_likeActionControllerDidUpdateNotification:)
name:FBSDKLikeActionControllerDidUpdateNotification
object:nil];
}
- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context
{
if (context == FBSDKLikeControlKVOLikeActionControllerContext) {
[self _likeActionControllerDidUpdateWithAnimated:NO];
} else {
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
}
static void FBSDKLikeControlApplyHorizontalAlignment(CGRect *frameRef,
CGRect bounds,
FBSDKLikeControlHorizontalAlignment alignment)
{
if (frameRef == NULL) {
return;
}
CGRect frame = *frameRef;
switch (alignment) {
case FBSDKLikeControlHorizontalAlignmentLeft:{
frame.origin.x = CGRectGetMinX(bounds);
break;
}
case FBSDKLikeControlHorizontalAlignmentCenter:{
frame.origin.x = CGRectGetMinX(bounds) + floorf((CGRectGetWidth(bounds) - CGRectGetWidth(frame)) / 2);
break;
}
case FBSDKLikeControlHorizontalAlignmentRight:{
frame.origin.x = CGRectGetMinX(bounds) + CGRectGetWidth(bounds) - CGRectGetWidth(frame);
break;
}
}
*frameRef = frame;
}
static CGFloat FBSDKLikeControlPaddedDistance(CGFloat distance, CGFloat padding, BOOL includeDistance)
{
return (distance == 0.0 ? 0.0 : (includeDistance ? distance : 0.0) + padding);
}
static CGSize FBSDKLikeControlCalculateContentSize(FBSDKLikeControlLayout layout)
{
return CGSizeMake(MAX(CGRectGetMaxX(layout.likeButtonFrame), CGRectGetMaxX(layout.auxiliaryViewFrame)),
MAX(CGRectGetMaxY(layout.likeButtonFrame), CGRectGetMaxY(layout.auxiliaryViewFrame)));
}
- (FBSDKLikeControlLayout)_layoutWithBounds:(CGRect)bounds
subviewSizingBlock:(fbsdk_like_control_sizing_block_t)subviewSizingBlock
{
FBSDKLikeControlLayout layout;
CGSize likeButtonSize = subviewSizingBlock(_likeButton, bounds.size);
layout.likeButtonFrame = CGRectMake(CGRectGetMinX(bounds),
CGRectGetMinY(bounds),
likeButtonSize.width,
likeButtonSize.height);
layout.auxiliaryViewFrame = CGRectZero;
UIView *auxiliaryView = [self _auxiliaryView];
CGFloat auxiliaryViewPadding = [self _auxiliaryViewPadding];
CGSize auxiliaryViewSize = CGSizeZero;
switch (self.likeControlAuxiliaryPosition) {
case FBSDKLikeControlAuxiliaryPositionInline:{
if (auxiliaryView) {
auxiliaryViewSize = CGSizeMake((CGRectGetWidth(bounds) -
auxiliaryViewPadding -
CGRectGetWidth(layout.likeButtonFrame)),
CGRectGetHeight(bounds));
auxiliaryViewSize = subviewSizingBlock(auxiliaryView, auxiliaryViewSize);
layout.auxiliaryViewFrame = CGRectMake(CGRectGetMinX(bounds),
CGRectGetMinY(bounds),
auxiliaryViewSize.width,
MAX(auxiliaryViewSize.height,
CGRectGetHeight(layout.likeButtonFrame)));
}
// align the views next to each other for sizing
FBSDKLikeControlApplyHorizontalAlignment(&layout.likeButtonFrame,
bounds,
FBSDKLikeControlHorizontalAlignmentLeft);
if (auxiliaryView) {
layout.auxiliaryViewFrame.origin.x = CGRectGetMaxX(layout.likeButtonFrame) + auxiliaryViewPadding;
}
// calculate the size before offsetting the horizontal alignment, using the total calculated width
layout.contentSize = FBSDKLikeControlCalculateContentSize(layout);
// layout the subviews next to each other
switch (self.likeControlHorizontalAlignment) {
case FBSDKLikeControlHorizontalAlignmentLeft:{
// already done
break;
}
case FBSDKLikeControlHorizontalAlignmentCenter:{
layout.likeButtonFrame.origin.x = floorf((CGRectGetWidth(bounds) - layout.contentSize.width) / 2);
if (auxiliaryView) {
layout.auxiliaryViewFrame.origin.x = (CGRectGetMaxX(layout.likeButtonFrame) +
auxiliaryViewPadding);
}
break;
}
case FBSDKLikeControlHorizontalAlignmentRight:{
layout.likeButtonFrame.origin.x = CGRectGetMaxX(bounds) - CGRectGetWidth(layout.likeButtonFrame);
if (auxiliaryView) {
layout.auxiliaryViewFrame.origin.x = (CGRectGetMinX(layout.likeButtonFrame) -
auxiliaryViewPadding -
CGRectGetWidth(layout.auxiliaryViewFrame));
}
break;
}
}
break;
}
case FBSDKLikeControlAuxiliaryPositionTop:{
if (auxiliaryView) {
auxiliaryViewSize = CGSizeMake(CGRectGetWidth(bounds),
(CGRectGetHeight(bounds) -
auxiliaryViewPadding -
CGRectGetHeight(layout.likeButtonFrame)));
auxiliaryViewSize = subviewSizingBlock(auxiliaryView, auxiliaryViewSize);
layout.auxiliaryViewFrame = CGRectMake(CGRectGetMinX(bounds),
CGRectGetMinY(bounds),
MAX(auxiliaryViewSize.width,
CGRectGetWidth(layout.likeButtonFrame)),
auxiliaryViewSize.height);
}
layout.likeButtonFrame.origin.y = FBSDKLikeControlPaddedDistance(CGRectGetMaxY(layout.auxiliaryViewFrame),
auxiliaryViewPadding,
YES);
// calculate the size before offsetting the horizontal alignment, using the total calculated width
layout.contentSize = FBSDKLikeControlCalculateContentSize(layout);
FBSDKLikeControlApplyHorizontalAlignment(&layout.likeButtonFrame, bounds, self.likeControlHorizontalAlignment);
FBSDKLikeControlApplyHorizontalAlignment(&layout.auxiliaryViewFrame,
bounds,
self.likeControlHorizontalAlignment);
break;
}
case FBSDKLikeControlAuxiliaryPositionBottom:{
if (auxiliaryView) {
auxiliaryViewSize = CGSizeMake(CGRectGetWidth(bounds),
(CGRectGetHeight(bounds) -
auxiliaryViewPadding -
CGRectGetHeight(layout.likeButtonFrame)));
auxiliaryViewSize = subviewSizingBlock(auxiliaryView, auxiliaryViewSize);
layout.auxiliaryViewFrame = CGRectMake(CGRectGetMinX(bounds),
CGRectGetMaxY(layout.likeButtonFrame) + auxiliaryViewPadding,
MAX(auxiliaryViewSize.width,
CGRectGetWidth(layout.likeButtonFrame)),
auxiliaryViewSize.height);
}
// calculate the size before offsetting the horizontal alignment, using the total calculated width
layout.contentSize = FBSDKLikeControlCalculateContentSize(layout);
FBSDKLikeControlApplyHorizontalAlignment(&layout.likeButtonFrame, bounds, self.likeControlHorizontalAlignment);
FBSDKLikeControlApplyHorizontalAlignment(&layout.auxiliaryViewFrame,
bounds,
self.likeControlHorizontalAlignment);
break;
}
}
return layout;
}
- (void)_likeActionControllerDidDisableNotification:(NSNotification *)notification
{
[self _updateEnabled];
}
- (void)_likeActionControllerDidUpdateNotification:(NSNotification *)notification
{
[self _ensureLikeActionController];
FBSDKLikeActionController *likeActionController = (FBSDKLikeActionController *)notification.object;
NSString *objectID = likeActionController.objectID;
if ([self.objectID isEqualToString:objectID]) {
BOOL animated = [notification.userInfo[FBSDKLikeActionControllerAnimatedKey] boolValue];
[self _likeActionControllerDidUpdateWithAnimated:animated];
}
}
- (void)_likeActionControllerDidUpdateWithAnimated:(BOOL)animated
{
FBSDKLikeActionController *likeActionController = _likeButton.likeActionController;
NSString *objectID = likeActionController.objectID;
if ([self.objectID isEqualToString:objectID]) {
_likeBoxView.text = _likeButton.likeActionController.likeCountString;
if (animated) {
void(^hideView)(UIView *) = ^(UIView *view){
view.alpha = 0.0;
CGRect frame = view.frame;
frame.origin.y += kFBLikeControlSocialSentenceAnimationOffset;
view.frame = frame;
};
[UIView animateWithDuration:kFBLikeControlAnimationDuration animations:^{
hideView(self->_socialSentenceLabel);
} completion:^(BOOL finished) {
self->_socialSentenceLabel.text = likeActionController.socialSentence;
[self setNeedsLayout];
[self setNeedsUpdateConstraints];
[self invalidateIntrinsicContentSize];
[self layoutIfNeeded];
hideView(self->_socialSentenceLabel);
[UIView animateWithDuration:kFBLikeControlAnimationDuration animations:^{
self->_socialSentenceLabel.alpha = 1.0;
[self setNeedsLayout];
[self layoutIfNeeded];
}];
}];
} else {
_socialSentenceLabel.text = likeActionController.socialSentence;
[self setNeedsLayout];
[self setNeedsUpdateConstraints];
[self invalidateIntrinsicContentSize];
}
[self sendActionsForControlEvents:UIControlEventValueChanged];
}
}
- (void)_updateEnabled
{
BOOL enabled = (!_isExplicitlyDisabled &&
self.objectID &&
![FBSDKLikeActionController isDisabled]);
BOOL currentEnabled = [self isEnabled];
[super setEnabled:enabled];
if (currentEnabled != enabled) {
[self invalidateIntrinsicContentSize];
[self setNeedsLayout];
}
}
- (void)_updateLikeBoxCaretPosition
{
if (self.likeControlStyle != FBSDKLikeControlStyleBoxCount) {
return;
}
switch (self.likeControlAuxiliaryPosition) {
case FBSDKLikeControlAuxiliaryPositionInline:{
switch (self.likeControlHorizontalAlignment) {
case FBSDKLikeControlHorizontalAlignmentLeft:
case FBSDKLikeControlHorizontalAlignmentCenter:{
_likeBoxView.caretPosition = FBSDKLikeBoxCaretPositionLeft;
break;
}
case FBSDKLikeControlHorizontalAlignmentRight:{
_likeBoxView.caretPosition = FBSDKLikeBoxCaretPositionRight;
break;
}
}
break;
}
case FBSDKLikeControlAuxiliaryPositionTop:{
_likeBoxView.caretPosition = FBSDKLikeBoxCaretPositionBottom;
break;
}
case FBSDKLikeControlAuxiliaryPositionBottom:{
_likeBoxView.caretPosition = FBSDKLikeBoxCaretPositionTop;
break;
}
}
}
@end
@@ -1,40 +0,0 @@
// 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.
#import <Foundation/Foundation.h>
#import <FBSDKCoreKit/FBSDKMacros.h>
/**
NS_ENUM (NSUInteger, FBSDKLikeObjectType)
Specifies the type of object referenced by the objectID for likes.
*/
typedef NS_ENUM(NSUInteger, FBSDKLikeObjectType)
{
/** The objectID refers to an unknown object type. */
FBSDKLikeObjectTypeUnknown = 0,
/** The objectID refers to an Open Graph object. */
FBSDKLikeObjectTypeOpenGraph,
/** The objectID refers to an Page object. */
FBSDKLikeObjectTypePage,
};
/**
Converts an FBLikeControlObjectType to an NSString.
*/
FBSDK_EXTERN NSString *NSStringFromFBSDKLikeObjectType(FBSDKLikeObjectType objectType);
@@ -1,32 +0,0 @@
// 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.
#import "FBSDKLikeObjectType.h"
NSString *NSStringFromFBSDKLikeObjectType(FBSDKLikeObjectType objectType)
{
switch (objectType) {
case FBSDKLikeObjectTypeUnknown:
return @"unknown";
case FBSDKLikeObjectTypeOpenGraph:
return @"open_graph";
case FBSDKLikeObjectTypePage:
return @"page";
}
return nil;
}
@@ -1,49 +0,0 @@
// 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.
#import <Foundation/Foundation.h>
/**
The common interface for components that initiate liking.
@see FBSDKLikeButton
@see FBSDKLikeControl
*/
@protocol FBSDKLiking <NSObject>
/**
The objectID for the object to like.
This value may be an Open Graph object ID or a string representation of an URL that describes an
Open Graph object. The objects may be public objects, like pages, or objects that are defined by your application.
*/
@property (nonatomic, copy) NSString *objectID;
/**
The type of object referenced by the objectID.
If the objectType is unknown, the control will determine the objectType by querying the server with the
objectID. Specifying a value for the objectType is an optimization that should be used if the type is known by the
consumer. Consider setting the objectType if it is known when setting the objectID.
*/
@property (nonatomic, assign) FBSDKLikeObjectType objectType;
@end
@@ -1,47 +0,0 @@
// 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.
#import <Foundation/Foundation.h>
#import <FBSDKShareKit/FBSDKSharing.h>
/**
A dialog for sharing content through Messenger.
SUPPORTED SHARE TYPES
- FBSDKShareLinkContent
- FBSDKShareMessengerOpenGraphMusicTemplateContent
- FBSDKShareMessengerMediaTemplateContent
- FBSDKShareMessengerGenericTemplateContent
UNSUPPORTED SHARE TYPES (DEPRECATED AUGUST 2018)
- FBSDKShareOpenGraphContent
- FBSDKSharePhotoContent
- FBSDKShareVideoContent
- Any other types that are not one of the four supported types listed above
*/
@interface FBSDKMessageDialog : NSObject <FBSDKSharingDialog>
/**
Convenience method to show a Message Share Dialog with content and a delegate.
@param content The content to be shared.
@param delegate The receiver's delegate.
*/
+ (instancetype)showWithContent:(id<FBSDKSharingContent>)content delegate:(id<FBSDKSharingDelegate>)delegate;
@end
@@ -1,243 +0,0 @@
// 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.
#import "FBSDKMessageDialog.h"
#import "FBSDKCoreKit+Internal.h"
#import "FBSDKShareCameraEffectContent.h"
#import "FBSDKShareConstants.h"
#import "FBSDKShareDefines.h"
#import "FBSDKShareError.h"
#import "FBSDKShareMessengerGenericTemplateContent.h"
#import "FBSDKShareMessengerMediaTemplateContent.h"
#import "FBSDKShareMessengerOpenGraphMusicTemplateContent.h"
#import "FBSDKShareOpenGraphContent.h"
#import "FBSDKShareUtility.h"
#import "FBSDKShareVideoContent.h"
#define FBSDK_MESSAGE_DIALOG_APP_SCHEME @"fb-messenger-share-api"
@implementation FBSDKMessageDialog
#pragma mark - Class Methods
+ (void)initialize
{
if ([FBSDKMessageDialog class] == self) {
[FBSDKInternalUtility checkRegisteredCanOpenURLScheme:FBSDK_CANOPENURL_MESSENGER];
[FBSDKServerConfigurationManager loadServerConfigurationWithCompletionBlock:NULL];
}
}
+ (instancetype)showWithContent:(id<FBSDKSharingContent>)content delegate:(id<FBSDKSharingDelegate>)delegate
{
FBSDKMessageDialog *dialog = [[self alloc] init];
dialog.shareContent = content;
dialog.delegate = delegate;
[dialog show];
return dialog;
}
#pragma mark - Properties
@synthesize delegate = _delegate;
@synthesize shareContent = _shareContent;
@synthesize shouldFailOnDataError = _shouldFailOnDataError;
#pragma mark - Public Methods
- (BOOL)canShow
{
return [self _canShowNative];
}
- (BOOL)show
{
NSError *error;
if (![self canShow]) {
error = [FBSDKShareError errorWithCode:FBSDKShareDialogNotAvailableErrorCode
message:@"Message dialog is not available."];
[self _invokeDelegateDidFailWithError:error];
return NO;
}
if (![self validateWithError:&error]) {
[self _invokeDelegateDidFailWithError:error];
return NO;
}
id<FBSDKSharingContent> shareContent = self.shareContent;
NSDictionary *parameters = [FBSDKShareUtility parametersForShareContent:shareContent
bridgeOptions:FBSDKShareBridgeOptionsDefault
shouldFailOnDataError:self.shouldFailOnDataError];
NSString *methodName = ([shareContent isKindOfClass:[FBSDKShareOpenGraphContent class]] ?
FBSDK_SHARE_OPEN_GRAPH_METHOD_NAME :
FBSDK_SHARE_METHOD_NAME);
FBSDKBridgeAPIRequest *request;
request = [FBSDKBridgeAPIRequest bridgeAPIRequestWithProtocolType:FBSDKBridgeAPIProtocolTypeNative
scheme:FBSDK_MESSAGE_DIALOG_APP_SCHEME
methodName:methodName
methodVersion:nil
parameters:parameters
userInfo:nil];
FBSDKServerConfiguration *configuration = [FBSDKServerConfigurationManager cachedServerConfiguration];
BOOL useSafariViewController = [configuration useSafariViewControllerForDialogName:FBSDKDialogConfigurationNameMessage];
FBSDKBridgeAPICallbackBlock completionBlock = ^(FBSDKBridgeAPIResponse *response) {
[self _handleCompletionWithDialogResults:response.responseParameters response:response];
[FBSDKInternalUtility unregisterTransientObject:self];
};
[[FBSDKApplicationDelegate sharedInstance] openBridgeAPIRequest:request
useSafariViewController:useSafariViewController
fromViewController:nil
completionBlock:completionBlock];
[self _logDialogShow];
[FBSDKInternalUtility registerTransientObject:self];
return YES;
}
- (BOOL)validateWithError:(NSError *__autoreleasing *)errorRef
{
if (self.shareContent) {
if ([self.shareContent isKindOfClass:[FBSDKShareLinkContent class]] ||
[self.shareContent isKindOfClass:[FBSDKShareMessengerGenericTemplateContent class]] ||
[self.shareContent isKindOfClass:[FBSDKShareMessengerMediaTemplateContent class]] ||
[self.shareContent isKindOfClass:[FBSDKShareMessengerOpenGraphMusicTemplateContent class]]) {
} else {
if (errorRef != NULL) {
NSString *message = [NSString stringWithFormat:@"Message dialog does not support %@.",
NSStringFromClass(self.shareContent.class)];
*errorRef = [FBSDKShareError requiredArgumentErrorWithName:@"shareContent"
message:message];
}
return NO;
}
}
return [FBSDKShareUtility validateShareContent:self.shareContent
bridgeOptions:FBSDKShareBridgeOptionsDefault
error:errorRef];
}
#pragma mark - Helper Methods
- (BOOL)_canShowNative
{
FBSDKServerConfiguration *configuration = [FBSDKServerConfigurationManager cachedServerConfiguration];
BOOL useNativeDialog = [configuration useNativeDialogForDialogName:FBSDKDialogConfigurationNameMessage];
return (useNativeDialog && [FBSDKInternalUtility isMessengerAppInstalled]);
}
- (void)_handleCompletionWithDialogResults:(NSDictionary *)results response:(FBSDKBridgeAPIResponse *)response
{
NSString *completionGesture = results[FBSDK_SHARE_RESULT_COMPLETION_GESTURE_KEY];
if ([completionGesture isEqualToString:FBSDK_SHARE_RESULT_COMPLETION_GESTURE_VALUE_CANCEL] ||
response.isCancelled) {
[self _invokeDelegateDidCancel];
} else if (response.error) {
[self _invokeDelegateDidFailWithError:response.error];
} else {
[self _invokeDelegateDidCompleteWithResults:results];
}
}
- (void)_invokeDelegateDidCancel
{
NSDictionary * parameters =@{
FBSDKAppEventParameterDialogOutcome : FBSDKAppEventsDialogOutcomeValue_Cancelled,
};
[FBSDKAppEvents logImplicitEvent:FBSDKAppEventNameFBSDKEventMessengerShareDialogResult
valueToSum:nil
parameters:parameters
accessToken:[FBSDKAccessToken currentAccessToken]];
if (!_delegate) {
return;
}
[_delegate sharerDidCancel:self];
}
- (void)_invokeDelegateDidCompleteWithResults:(NSDictionary *)results
{
NSDictionary * parameters =@{
FBSDKAppEventParameterDialogOutcome : FBSDKAppEventsDialogOutcomeValue_Completed,
};
[FBSDKAppEvents logImplicitEvent:FBSDKAppEventNameFBSDKEventMessengerShareDialogResult
valueToSum:nil
parameters:parameters
accessToken:[FBSDKAccessToken currentAccessToken]];
if (!_delegate) {
return;
}
[_delegate sharer:self didCompleteWithResults:[results copy]];
}
- (void)_invokeDelegateDidFailWithError:(NSError *)error
{
NSMutableDictionary * parameters = [NSMutableDictionary dictionaryWithObjectsAndKeys:FBSDKAppEventsDialogOutcomeValue_Failed, FBSDKAppEventParameterDialogOutcome, nil];
if (error) {
parameters[FBSDKAppEventParameterDialogErrorMessage] = [NSString stringWithFormat:@"%@", error];
}
[FBSDKAppEvents logImplicitEvent:FBSDKAppEventNameFBSDKEventMessengerShareDialogResult
valueToSum:nil
parameters:parameters
accessToken:[FBSDKAccessToken currentAccessToken]];
if (!_delegate) {
return;
}
[_delegate sharer:self didFailWithError:error];
}
- (void)_logDialogShow
{
NSString *contentType;
if([self.shareContent isKindOfClass:[FBSDKShareOpenGraphContent class]]) {
contentType = FBSDKAppEventsDialogShareContentTypeOpenGraph;
} else if ([self.shareContent isKindOfClass:[FBSDKShareLinkContent class]]) {
contentType = FBSDKAppEventsDialogShareContentTypeStatus;
} else if ([self.shareContent isKindOfClass:[FBSDKSharePhotoContent class]]) {
contentType = FBSDKAppEventsDialogShareContentTypePhoto;
} else if ([self.shareContent isKindOfClass:[FBSDKShareVideoContent class]]) {
contentType = FBSDKAppEventsDialogShareContentTypeVideo;
} else if ([self.shareContent isKindOfClass:[FBSDKShareMessengerGenericTemplateContent class]]) {
contentType = FBSDKAppEventsDialogShareContentTypeMessengerGenericTemplate;
} else if ([self.shareContent isKindOfClass:[FBSDKShareMessengerMediaTemplateContent class]]) {
contentType = FBSDKAppEventsDialogShareContentTypeMessengerMediaTemplate;
} else if ([self.shareContent isKindOfClass:[FBSDKShareMessengerOpenGraphMusicTemplateContent class]]) {
contentType = FBSDKAppEventsDialogShareContentTypeMessengerOpenGraphMusicTemplate;
} else {
contentType = FBSDKAppEventsDialogShareContentTypeUnknown;
}
NSDictionary *parameters = @{FBSDKAppEventParameterDialogShareContentType : contentType,
FBSDKAppEventParameterDialogShareContentUUID : self.shareContent.shareUUID ?: [NSNull null],
FBSDKAppEventParameterDialogShareContentPageID : self.shareContent.pageID ?: [NSNull null]};
[FBSDKAppEvents logImplicitEvent:FBSDKAppEventNameFBSDKEventMessengerShareDialogShow
valueToSum:nil
parameters:parameters
accessToken:[FBSDKAccessToken currentAccessToken]];
}
@end
@@ -1,33 +0,0 @@
// 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.
#import <UIKit/UIKit.h>
#import <FBSDKCoreKit/FBSDKButton.h>
#import <FBSDKShareKit/FBSDKSharingButton.h>
/**
A button to send content through Messenger.
Tapping the receiver will invoke the FBSDKShareDialog with the attached shareContent. If the dialog cannot
be shown, the button will be disable.
*/
@interface FBSDKSendButton : FBSDKButton <FBSDKSharingButton>
@end
@@ -1,97 +0,0 @@
// 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.
#import "FBSDKSendButton.h"
#import "FBSDKCoreKit+Internal.h"
#import "FBSDKMessageDialog.h"
#import "FBSDKMessengerIcon.h"
@interface FBSDKSendButton () <FBSDKButtonImpressionTracking>
@end
@implementation FBSDKSendButton
{
FBSDKMessageDialog *_dialog;
}
#pragma mark - Properties
- (id<FBSDKSharingContent>)shareContent
{
return _dialog.shareContent;
}
- (void)setShareContent:(id<FBSDKSharingContent>)shareContent
{
_dialog.shareContent = shareContent;
[self checkImplicitlyDisabled];
}
#pragma mark - FBSDKButtonImpressionTracking
- (NSDictionary *)analyticsParameters
{
return nil;
}
- (NSString *)impressionTrackingEventName
{
return FBSDKAppEventNameFBSDKSendButtonImpression;
}
- (NSString *)impressionTrackingIdentifier
{
return @"send";
}
#pragma mark - FBSDKButton
- (void)configureButton
{
NSString *title =
NSLocalizedStringWithDefaultValue(@"SendButton.Send", @"FacebookSDK", [FBSDKInternalUtility bundleForStrings],
@"Send",
@"The label for FBSDKSendButton");
UIColor *backgroundColor = [UIColor colorWithRed:0.0 green:132.0/255.0 blue:1.0 alpha:1.0];
UIColor *highlightedColor = [UIColor colorWithRed:0.0 green:111.0/255.0 blue:1.0 alpha:1.0];
[self configureWithIcon:[[FBSDKMessengerIcon alloc] init]
title:title
backgroundColor:backgroundColor
highlightedColor:highlightedColor];
[self addTarget:self action:@selector(_share:) forControlEvents:UIControlEventTouchUpInside];
_dialog = [[FBSDKMessageDialog alloc] init];
}
- (BOOL)isImplicitlyDisabled
{
return ![_dialog canShow] || ![_dialog validateWithError:NULL];
}
#pragma mark - Helper Methods
- (void)_share:(id)sender
{
[self logTapEventWithEventName:FBSDKAppEventNameFBSDKSendButtonDidTap parameters:[self analyticsParameters]];
[_dialog show];
}
@end
@@ -1,94 +0,0 @@
// 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.
#import <Foundation/Foundation.h>
#import <FBSDKCoreKit/FBSDKAccessToken.h>
#import <FBSDKShareKit/FBSDKShareOpenGraphObject.h>
#import <FBSDKShareKit/FBSDKSharing.h>
/**
A utility class for sharing through the graph API. Using this class requires an access token that
has been granted the "publish_actions" permission.
FBSDKShareAPI network requests are scheduled on the current run loop in the default run loop mode
(like NSURLConnection). If you want to use FBSDKShareAPI in a background thread, you must manage the run loop
yourself.
*/
@interface FBSDKShareAPI : NSObject <FBSDKSharing>
/**
Convenience method to build up a share API with content and a delegate.
@param content The content to be shared.
@param delegate The receiver's delegate.
*/
+ (instancetype)shareWithContent:(id<FBSDKSharingContent>)content delegate:(id<FBSDKSharingDelegate>)delegate;
/**
The message the person has provided through the custom dialog that will accompany the share content.
*/
@property (nonatomic, copy) NSString *message;
/**
The graph node to which content should be shared.
*/
@property (nonatomic, copy) NSString *graphNode;
/**
The access token used when performing a share. The access token must have the "publish_actions"
permission granted.
Defaults to [FBSDKAccessToken currentAccessToken]. Setting this to nil will revert the access token to
[FBSDKAccessToken currentAccessToken].
*/
@property (nonatomic, strong) FBSDKAccessToken *accessToken;
/**
A Boolean value that indicates whether the receiver can send the share.
May return NO if the appropriate Facebook app is not installed and is required or an access token is
required but not available. This method does not validate the content on the receiver, so this can be checked before
building up the content.
@see [FBSDKSharing validateWithError:]
@return YES if the receiver can send, otherwise NO.
*/
- (BOOL)canShare;
/**
Creates an User Owned Open Graph object without an action.
@param openGraphObject The open graph object to create.
Use this method to create an object alone, when an action is not going to be posted with the object. If
the object will be used within an action, just put the object in the action and share that as the shareContent and the
object will be created in the process. The delegate will be messaged with the results.
Also see https://developers.facebook.com/docs/sharing/opengraph/object-api#objectapi-creatinguser
@return YES if the receiver was able to send the request to create the object, otherwise NO.
*/
- (BOOL)createOpenGraphObject:(FBSDKShareOpenGraphObject *)openGraphObject;
/**
Begins the send from the receiver.
@return YES if the receiver was able to send the share, otherwise NO.
*/
- (BOOL)share;
@end
@@ -1,825 +0,0 @@
// 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.
#import "FBSDKShareAPI.h"
#if !TARGET_OS_TV
#import <AssetsLibrary/AssetsLibrary.h>
#endif
#import <FBSDKCoreKit/FBSDKGraphRequest.h>
#import <FBSDKCoreKit/FBSDKGraphRequestDataAttachment.h>
#import "FBSDKCoreKit+Internal.h"
#import "FBSDKShareConstants.h"
#import "FBSDKShareDefines.h"
#import "FBSDKShareError.h"
#import "FBSDKShareLinkContent.h"
#import "FBSDKShareOpenGraphAction.h"
#import "FBSDKShareOpenGraphContent.h"
#import "FBSDKShareOpenGraphObject.h"
#import "FBSDKSharePhoto.h"
#import "FBSDKSharePhotoContent.h"
#import "FBSDKShareUtility.h"
#import "FBSDKShareVideo.h"
#import "FBSDKShareVideoContent.h"
#import "FBSDKVideoUploader.h"
static NSString *const FBSDKShareAPIDefaultGraphNode = @"me";
static NSString *const FBSDKShareAPIPhotosEdge = @"photos";
static NSString *const FBSDKShareAPIVideosEdge = @"videos";
static NSMutableArray *g_pendingFBSDKShareAPI;
@interface FBSDKShareAPI () <FBSDKVideoUploaderDelegate>
@end
@implementation FBSDKShareAPI {
NSFileHandle *_fileHandle;
#if !TARGET_OS_TV
ALAssetRepresentation *_assetRepresentation;
#endif
}
#pragma mark - Class Methods
+ (instancetype)shareWithContent:(id<FBSDKSharingContent>)content delegate:(id<FBSDKSharingDelegate>)delegate
{
FBSDKShareAPI *API = [[self alloc] init];
API.shareContent = content;
API.delegate = delegate;
[API share];
return API;
}
#pragma mark - Properties
@synthesize delegate = _delegate;
@synthesize shareContent = _shareContent;
@synthesize shouldFailOnDataError = _shouldFailOnDataError;
@synthesize accessToken = _accessToken;
#pragma mark - Object Lifecycle
#if !TARGET_OS_TV
+ (ALAssetsLibrary *)defaultAssetsLibrary {
static dispatch_once_t pred = 0;
static ALAssetsLibrary *library = nil;
dispatch_once(&pred, ^{
library = [[fbsdkdfl_ALAssetsLibraryClass() alloc] init];
});
return library;
}
#endif
+ (void)initialize
{
if (self == [FBSDKShareAPI class]) {
g_pendingFBSDKShareAPI = [[NSMutableArray alloc] init];
}
}
- (instancetype)init
{
if ((self = [super init])) {
_graphNode = FBSDKShareAPIDefaultGraphNode;
}
return self;
}
#pragma mark - Public Methods
- (BOOL)canShare
{
return YES;
}
- (BOOL)createOpenGraphObject:(FBSDKShareOpenGraphObject *)openGraphObject
{
NSError *error;
if (![self canShare]) {
NSString *message = @"Share API is not available; verify 'canShare' returns YES";
error = [FBSDKShareError errorWithCode:FBSDKShareDialogNotAvailableErrorCode message:message];
[_delegate sharer:self didFailWithError:error];
return NO;
}
if (![self _hasPublishActions]) {
NSString *message = @"Warning: Access token is missing publish_actions permissions";
[FBSDKLogger singleShotLogEntry:FBSDKLoggingBehaviorDeveloperErrors logEntry:message];
}
if (!openGraphObject) {
error = [FBSDKShareError requiredArgumentErrorWithName:@"openGraphObject" message:nil];
[_delegate sharer:self didFailWithError:error];
return NO;
}
FBSDKGraphRequestConnection *connection = [[FBSDKGraphRequestConnection alloc] init];
void(^completionHandler)(id) = ^(NSDictionary *result) {
[self->_delegate sharer:self didCompleteWithResults:result];
};
if (![self _stageOpenGraphObject:openGraphObject
connection:connection
stagingHandler:NULL
completionHandler:completionHandler]) {
return NO;
}
[connection start];
return YES;
}
- (BOOL)share
{
NSError *error;
if (![self canShare]) {
NSString *message = @"Share API is not available; verify 'canShare' returns YES";
error = [FBSDKShareError errorWithCode:FBSDKShareDialogNotAvailableErrorCode message:message];
[_delegate sharer:self didFailWithError:error];
return NO;
}
if (![self _hasPublishActions]) {
NSString *message = @"Warning: Access token is missing publish_actions permissions";
[FBSDKLogger singleShotLogEntry:FBSDKLoggingBehaviorDeveloperErrors logEntry:message];
}
if (![self validateWithError:&error]) {
[_delegate sharer:self didFailWithError:error];
return NO;
}
id<FBSDKSharingContent> shareContent = self.shareContent;
if ([shareContent isKindOfClass:[FBSDKShareLinkContent class]]) {
return [self _shareLinkContent:(FBSDKShareLinkContent *)shareContent];
} else if ([shareContent isKindOfClass:[FBSDKSharePhotoContent class]]) {
return [self _sharePhotoContent:(FBSDKSharePhotoContent *)shareContent];
} else if ([shareContent isKindOfClass:[FBSDKShareVideoContent class]]) {
return [self _shareVideoContent:(FBSDKShareVideoContent *)shareContent];
} else if ([shareContent isKindOfClass:[FBSDKShareOpenGraphContent class]]) {
return [self _shareOpenGraphContent:(FBSDKShareOpenGraphContent *)shareContent];
} else {
return NO;
}
}
- (BOOL)validateWithError:(NSError *__autoreleasing *)errorRef
{
id<FBSDKSharingContent> shareContent = self.shareContent;
if (!shareContent) {
if (errorRef != NULL) {
*errorRef = [FBSDKShareError requiredArgumentErrorWithName:@"shareContent" message:@"Share content cannot be null."];
}
return NO;
}
if ([shareContent isKindOfClass:[FBSDKShareVideoContent class]]) {
if (shareContent.peopleIDs.count > 0) {
if (errorRef != NULL) {
*errorRef = [FBSDKShareError invalidArgumentErrorWithName:@"peopleIDs" value:shareContent.peopleIDs message:@"Cannot specify peopleIDs with FBSDKShareVideoContent."];
}
return NO;
}
if (shareContent.placeID) {
if (errorRef != NULL) {
*errorRef = [FBSDKShareError invalidArgumentErrorWithName:@"placeID" value:shareContent.placeID message:@"Cannot specify place ID with FBSDKShareVideoContent."];
}
return NO;
}
}
if (errorRef != NULL){
*errorRef = nil;
}
return [FBSDKShareUtility validateShareContent:shareContent bridgeOptions:FBSDKShareBridgeOptionsDefault error:errorRef];
}
- (FBSDKAccessToken *)accessToken
{
return _accessToken ?: [FBSDKAccessToken currentAccessToken];
}
#pragma mark - Helper Methods
- (NSString *)_graphPathWithSuffix:(NSString *)suffix, ... NS_REQUIRES_NIL_TERMINATION
{
NSMutableString *graphPath = [[NSMutableString alloc] initWithString:self.graphNode];
va_list args;
va_start(args, suffix);
for (NSString *arg = suffix; arg != nil; arg = va_arg(args, NSString *)) {
[graphPath appendFormat:@"/%@", arg];
}
va_end(args);
return graphPath;
}
- (void)_addCommonParameters:(NSMutableDictionary *)parameters content:(id<FBSDKSharingContent>)content
{
if (content.peopleIDs.count > 0) {
NSString *tags;
if ([content isKindOfClass:[FBSDKSharePhotoContent class]]) {
NSMutableArray *tagsArray = [[NSMutableArray alloc] init];
for (NSString *peopleID in content.peopleIDs) {
[tagsArray addObject:@{ @"tag_uid" : peopleID }];
}
NSData *tagsJSON = [NSJSONSerialization dataWithJSONObject:tagsArray options:0 error:nil];
tags = [[NSString alloc] initWithData:tagsJSON encoding:NSUTF8StringEncoding];
} else {
tags = [content.peopleIDs componentsJoinedByString:@","];
}
[FBSDKInternalUtility dictionary:parameters setObject:tags forKey:@"tags"];
}
[FBSDKInternalUtility dictionary:parameters setObject:content.placeID forKey:@"place"];
[FBSDKInternalUtility dictionary:parameters setObject:content.ref forKey:@"ref"];
}
- (BOOL)_hasPublishActions
{
return [self.accessToken.permissions containsObject:@"publish_actions"];
}
- (BOOL)_shareLinkContent:(FBSDKShareLinkContent *)linkContent
{
FBSDKGraphRequestHandler completionHandler = ^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (!self->_delegate) {
return;
}
if (error) {
[self->_delegate sharer:self didFailWithError:error];
} else {
result = [FBSDKTypeUtility dictionaryValue:result];
NSMutableDictionary *shareResults = [[NSMutableDictionary alloc] init];
[FBSDKInternalUtility dictionary:shareResults setObject:FBSDK_SHARE_RESULT_COMPLETION_GESTURE_VALUE_POST
forKey:FBSDK_SHARE_RESULT_COMPLETION_GESTURE_KEY];
[FBSDKInternalUtility dictionary:shareResults setObject:[FBSDKTypeUtility stringValue:result[@"id"]]
forKey:FBSDK_SHARE_RESULT_POST_ID_KEY];
[self->_delegate sharer:self didCompleteWithResults:shareResults];
}
};
NSMutableDictionary *parameters = [[NSMutableDictionary alloc] init];
[self _addCommonParameters:parameters content:linkContent];
[FBSDKInternalUtility dictionary:parameters setObject:self.message forKey:@"message"];
[FBSDKInternalUtility dictionary:parameters setObject:linkContent.contentURL forKey:@"link"];
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[FBSDKInternalUtility dictionary:parameters setObject:linkContent.imageURL forKey:@"picture"];
[FBSDKInternalUtility dictionary:parameters setObject:linkContent.contentTitle forKey:@"name"];
[FBSDKInternalUtility dictionary:parameters setObject:linkContent.contentDescription forKey:@"description"];
#pragma clang diagnostic pop
[[[FBSDKGraphRequest alloc] initWithGraphPath:[self _graphPathWithSuffix:@"feed", nil]
parameters:parameters
tokenString:self.accessToken.tokenString
version:nil
HTTPMethod:@"POST"] startWithCompletionHandler:completionHandler];
return YES;
}
- (BOOL)_shareOpenGraphContent:(FBSDKShareOpenGraphContent *)openGraphContent
{
// In order to create a new Open Graph action using a custom object that does not already exist (objectID or URL), you
// must first send a request to post the object and then another to post the action. If a local image is supplied
// with the object or action, that must be staged first and then referenced by the staging URL that is returned by
// that request.
FBSDKShareOpenGraphAction *action = openGraphContent.action;
FBSDKGraphRequestConnection *connection = [[FBSDKGraphRequestConnection alloc] init];
void(^stagingHandler)(NSDictionary *) = ^(NSDictionary *stagedContainer) {
NSMutableDictionary *parameters = [NSMutableDictionary dictionaryWithDictionary:stagedContainer];
[self _addCommonParameters:parameters content:openGraphContent];
[FBSDKInternalUtility dictionary:parameters setObject:self.message forKey:@"message"];
FBSDKGraphRequestHandler requestHandler = ^(FBSDKGraphRequestConnection *requestConnection,
id result,
NSError *requestError) {
if (!self->_delegate) {
return;
}
if (requestError) {
NSError *error = [FBSDKShareError errorWithCode:FBSDKShareOpenGraphErrorCode
message:@"Error sharing Open Graph content"
underlyingError:requestError];
[self->_delegate sharer:self didFailWithError:error];
} else if (result) {
NSMutableDictionary *shareResults = [[NSMutableDictionary alloc] init];
[FBSDKInternalUtility dictionary:shareResults setObject:FBSDK_SHARE_RESULT_COMPLETION_GESTURE_VALUE_POST
forKey:FBSDK_SHARE_RESULT_COMPLETION_GESTURE_KEY];
[FBSDKInternalUtility dictionary:shareResults setObject:[FBSDKTypeUtility stringValue:result[@"id"]]
forKey:FBSDK_SHARE_RESULT_POST_ID_KEY];
[self->_delegate sharer:self didCompleteWithResults:shareResults];
}
};
NSString *graphPath = [self _graphPathWithSuffix:[FBSDKUtility URLEncode:action.actionType], nil];
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc] initWithGraphPath:graphPath
parameters:parameters
tokenString:self.accessToken.tokenString
version:nil
HTTPMethod:@"POST"];
[self _connection:connection addRequest:request completionHandler:requestHandler];
[connection start];
};
if (![self _stageOpenGraphValueContainer:action connection:connection stagingHandler:stagingHandler]) {
return NO;
}
return YES;
}
- (BOOL)_sharePhotoContent:(FBSDKSharePhotoContent *)photoContent
{
NSArray *photos = photoContent.photos;
NSMutableArray *requests = [[NSMutableArray alloc] init];
for (FBSDKSharePhoto *photo in photos) {
UIImage *image = photo.image;
if (!image && [photo.imageURL isFileURL]) {
image = [UIImage imageWithContentsOfFile:[photo.imageURL path]];
}
if (image) {
NSString *graphPath = [self _graphPathWithSuffix:FBSDKShareAPIPhotosEdge, nil];
NSMutableDictionary *parameters = [[NSMutableDictionary alloc] init];
[self _addCommonParameters:parameters content:photoContent];
NSString *caption = photo.caption ?: self.message;
[FBSDKInternalUtility dictionary:parameters setObject:caption forKey:@"caption"];
parameters[@"picture"] = image;
[requests addObject:[[FBSDKGraphRequest alloc] initWithGraphPath:graphPath
parameters:parameters
tokenString:self.accessToken.tokenString
version:nil
HTTPMethod:@"POST"]];
}
}
NSUInteger requestCount = [requests count];
NSMutableArray *results = [[NSMutableArray alloc] init];
NSMutableArray *errors = [[NSMutableArray alloc] init];
__block NSUInteger completedCount = 0;
FBSDKGraphRequestHandler completionHandler = ^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
result = [FBSDKTypeUtility dictionaryValue:result];
[FBSDKInternalUtility array:results addObject:result];
[FBSDKInternalUtility array:errors addObject:error];
if (++completedCount != requestCount) {
return;
}
if (!self->_delegate) {
return;
}
if ([errors count]) {
[self->_delegate sharer:self didFailWithError:errors[0]];
} else if ([results count]) {
NSArray *individualPhotoIDs = [results valueForKeyPath:@"id"];
// each photo upload will be merged into the same post, so grab the post_id from the first and use that
NSMutableDictionary *shareResults = [[NSMutableDictionary alloc] init];
[FBSDKInternalUtility dictionary:shareResults setObject:FBSDK_SHARE_RESULT_COMPLETION_GESTURE_VALUE_POST
forKey:FBSDK_SHARE_RESULT_COMPLETION_GESTURE_KEY];
NSDictionary *firstResult = [FBSDKTypeUtility dictionaryValue:results[0]];
[FBSDKInternalUtility dictionary:shareResults setObject:[FBSDKTypeUtility stringValue:firstResult[@"post_id"]]
forKey:FBSDK_SHARE_RESULT_POST_ID_KEY];
[FBSDKInternalUtility dictionary:shareResults setObject:individualPhotoIDs forKey:FBSDK_SHARE_RESULT_PHOTO_IDS_KEY];
[self->_delegate sharer:self didCompleteWithResults:shareResults];
}
};
for (FBSDKGraphRequest *request in requests) {
[request startWithCompletionHandler:completionHandler];
}
return YES;
}
- (BOOL)_shareVideoContent:(FBSDKShareVideoContent *)videoContent
{
NSMutableDictionary *parameters = [[NSMutableDictionary alloc] init];
[self _addCommonParameters:parameters content:videoContent];
[FBSDKInternalUtility dictionary:parameters setObject:self.message forKey:@"description"];
if ([self.accessToken.permissions containsObject:@"ads_management"]) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
FBSDKSharePhoto *photo = videoContent.previewPhoto;
#pragma clang diagnostic pop
UIImage *image = photo.image;
if (!image && [photo.imageURL isFileURL]) {
image = [UIImage imageWithContentsOfFile:[photo.imageURL path]];
}
[FBSDKInternalUtility dictionary:parameters setObject:image forKey:@"thumb"];
}
FBSDKShareVideo *video = videoContent.video;
NSURL *videoURL = video.videoURL;
if ([videoURL isFileURL]) {
NSError *fileError;
_fileHandle = [NSFileHandle fileHandleForReadingFromURL:videoURL error:&fileError];
if (!_fileHandle) {
[_delegate sharer:self didFailWithError:fileError];
return NO;
}
if (![self _addToPendingShareAPI]) {
return NO;
}
FBSDKVideoUploader *videoUploader = [[FBSDKVideoUploader alloc] initWithVideoName:[videoURL lastPathComponent]
videoSize:(unsigned long)[_fileHandle seekToEndOfFile]
parameters:parameters
delegate:self];
videoUploader.graphNode = self.graphNode;
[videoUploader start];
return YES;
} else if (videoURL) {
#if TARGET_OS_TV
return NO;
#else
if (![self _addToPendingShareAPI]) {
return NO;
}
[[FBSDKShareAPI defaultAssetsLibrary] assetForURL:videoURL resultBlock:^(ALAsset *asset) {
self->_assetRepresentation = [asset defaultRepresentation];
NSUInteger size = (NSUInteger)self->_assetRepresentation.size;
FBSDKVideoUploader *videoUploader = [[FBSDKVideoUploader alloc] initWithVideoName:[videoURL lastPathComponent]
videoSize:size
parameters:parameters
delegate:self];
videoUploader.graphNode = self.graphNode;
[videoUploader start];
} failureBlock:^(NSError *error) {
[self->_delegate sharer:self didFailWithError:error];
}];
return YES;
#endif
} else {
return NO;
}
}
- (BOOL)_addEncodedParametersToDictionary:(NSMutableDictionary *)parameters
key:(NSString *)key
value:(id)value
error:(NSError * __autoreleasing *)errorRef
{
if ([value isKindOfClass:[NSString class]] ||
[value isKindOfClass:[NSNumber class]] ||
[value isKindOfClass:[NSNull class]]) {
parameters[key] = value;
} else if ([value isKindOfClass:[NSArray class]]) {
__block BOOL didEncode = YES;
[(NSArray *)value enumerateObjectsUsingBlock:^(id subvalue, NSUInteger idx, BOOL *stop) {
NSString *subkey = [[NSString alloc] initWithFormat:@"%@[%lu]", key, (unsigned long)idx];
if (![self _addEncodedParametersToDictionary:parameters key:subkey value:subvalue error:errorRef]) {
*stop = YES;
didEncode = NO;
}
}];
if (!didEncode) {
return NO;
}
} else if ([value isKindOfClass:[NSDictionary class]]) {
__block BOOL didEncode = YES;
[(NSDictionary *)value enumerateKeysAndObjectsUsingBlock:^(id subkey, id subvalue, BOOL *stop) {
subkey = [[NSString alloc] initWithFormat:@"%@[%@]", key, subkey];
if (![self _addEncodedParametersToDictionary:parameters key:subkey value:subvalue error:errorRef]) {
*stop = YES;
didEncode = NO;
}
}];
if (!didEncode) {
return NO;
}
} else {
if (errorRef != NULL) {
*errorRef = [FBSDKShareError invalidArgumentErrorWithName:key value:value message:nil];
}
return NO;
}
if (errorRef != NULL) {
*errorRef = nil;
}
return YES;
}
- (BOOL)_stageArray:(NSArray *)array
connection:(FBSDKGraphRequestConnection *)connection
stagingHandler:(void(^)(NSArray *stagedArray))stagingHandler
{
__block BOOL result = YES;
__block NSUInteger pendingCount = 1;
NSMutableArray *stagedArray = [[NSMutableArray alloc] initWithArray:array];
void(^itemDidFail)(void) = ^{
if (!result) {
return;
}
result = NO;
};
void(^itemDidSucceed)(void) = ^{
if (!result) {
return;
}
if ((--pendingCount == 0) && (stagingHandler != NULL)) {
stagingHandler(stagedArray);
}
};
[array enumerateObjectsUsingBlock:^(id item, NSUInteger idx, BOOL *stop) {
pendingCount++;
void(^itemHandler)(id) = ^(id stagedValue) {
if (stagedValue) {
stagedArray[idx] = stagedValue;
itemDidSucceed();
} else {
NSError *error = [FBSDKShareError invalidArgumentErrorWithName:@"value"
value:item
message:@"Error staging object."];
[self->_delegate sharer:self didFailWithError:error];
itemDidFail();
*stop = YES;
result = NO;
}
};
if (![self _stageValue:item connection:connection stagingHandler:itemHandler]) {
itemDidFail();
*stop = YES;
result = NO;
}
}];
if (result) {
itemDidSucceed();
}
return result;
}
- (BOOL)_stageOpenGraphObject:(FBSDKShareOpenGraphObject *)openGraphObject
connection:(FBSDKGraphRequestConnection *)connection
stagingHandler:(void(^)(id stagedObject))stagingHandler
completionHandler:(void(^)(NSDictionary *result))completionHandler
{
NSString *type = [FBSDKTypeUtility stringValue:openGraphObject[@"og:type"]];
if (!type) {
NSString *message = @"Open Graph objects must contain a og:type value.";
NSError *error = [FBSDKShareError requiredArgumentErrorWithName:@"og:type" message:message];
[_delegate sharer:self didFailWithError:error];
return NO;
}
void(^containerHandler)(NSDictionary *) = ^(NSDictionary *stagedContainer) {
NSError *JSONError;
NSString *objectString = [FBSDKInternalUtility JSONStringForObject:stagedContainer
error:&JSONError
invalidObjectHandler:NULL];
if (!objectString) {
[self->_delegate sharer:self didFailWithError:JSONError];
return;
}
NSString *graphPath = [self _graphPathWithSuffix:@"objects", type, nil];
NSDictionary *parameters = @{ @"object": objectString };
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc] initWithGraphPath:graphPath
parameters:parameters
tokenString:self.accessToken.tokenString
version:nil
HTTPMethod:@"POST"];
FBSDKGraphRequestHandler requestCompletionHandler = ^(FBSDKGraphRequestConnection *requestConnection,
id result,
NSError *requestError) {
if (!self->_delegate) {
return;
}
if (requestError) {
NSString *message = [[NSString alloc] initWithFormat:@"Error creating Open Graph object: %@",
requestError.description];
NSError *error = [FBSDKShareError errorWithCode:FBSDKShareOpenGraphErrorCode
message:message
underlyingError:requestError];
[self->_delegate sharer:self didFailWithError:error];
} else if (completionHandler != NULL) {
completionHandler([FBSDKTypeUtility dictionaryValue:result]);
}
};
NSString *batchEntryName = [self _connection:connection
addRequest:request
completionHandler:requestCompletionHandler];
if (stagingHandler != NULL) {
stagingHandler([[NSString alloc] initWithFormat:@"{result=%@:$.id}", batchEntryName]);
}
};
return [self _stageOpenGraphValueContainer:openGraphObject connection:connection stagingHandler:containerHandler];
return YES;
}
- (BOOL)_stageOpenGraphValueContainer:(id<FBSDKShareOpenGraphValueContaining>)container
connection:(FBSDKGraphRequestConnection *)connection
stagingHandler:(void(^)(NSDictionary *stagedContainer))stagingHandler
{
__block BOOL result = YES;
__block NSUInteger pendingCount = 1;
NSMutableDictionary *stagedContainer = [[NSMutableDictionary alloc] init];
void(^itemDidFail)(void) = ^{
if (!result) {
return;
}
result = NO;
};
void(^itemDidSucceed)(void) = ^{
if (!result) {
return;
}
if ((--pendingCount == 0) && (stagingHandler != NULL)) {
stagingHandler(stagedContainer);
}
};
BOOL isAction = [container isKindOfClass:[FBSDKShareOpenGraphAction class]];
[container enumerateKeysAndObjectsUsingBlock:^(NSString *key, id object, BOOL *stop) {
pendingCount++;
// The server does not understand custom namespaces remove them until the server is fixed
NSString *namespace;
key = [FBSDKShareUtility getOpenGraphNameAndNamespaceFromFullName:key namespace:&namespace];
if (namespace && !isAction) {
if (!stagedContainer[namespace]) {
stagedContainer[namespace] = [[NSMutableDictionary alloc] init];
}
}
void(^itemHandler)(id) = ^(id stagedValue) {
if (stagedValue) {
if (isAction) {
NSError *error;
if (![self _addEncodedParametersToDictionary:stagedContainer key:key value:stagedValue error:&error]) {
[self->_delegate sharer:self didFailWithError:error];
itemDidFail();
return;
}
} else {
NSMutableDictionary *valueContainer = (namespace ? stagedContainer[namespace] : stagedContainer);
valueContainer[key] = stagedValue;
}
}
itemDidSucceed();
};
if (![self _stageValue:object connection:connection stagingHandler:itemHandler]) {
*stop = YES;
result = NO;
}
}];
if (result) {
itemDidSucceed();
}
return result;
}
- (BOOL)_stagePhoto:(FBSDKSharePhoto *)photo
connection:(FBSDKGraphRequestConnection *)connection
stagingHandler:(void(^)(id stagedPhoto))stagingHandler
{
if (photo.imageURL) {
NSMutableDictionary *stagedPhoto = [[NSMutableDictionary alloc]initWithDictionary: @{
@"url": photo.imageURL.absoluteString,
@"user_generated": @(photo.userGenerated),
}];
[FBSDKInternalUtility dictionary:stagedPhoto setObject:photo.caption forKey:@"caption"];
if (stagingHandler) {
stagingHandler(stagedPhoto);
}
return YES;
} else if (photo.image) {
NSString *graphPath = @"/me/staging_resources";
NSDictionary *parameters = @{ @"file": photo.image };
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc] initWithGraphPath:graphPath
parameters:parameters
tokenString:self.accessToken.tokenString
version:nil
HTTPMethod:@"POST"];
FBSDKGraphRequestHandler completionHandler = ^(FBSDKGraphRequestConnection *requestConnection,
id result,
NSError *requestError) {
NSString *stagedPhotoURLString = [FBSDKTypeUtility stringValue:result[@"uri"]];
if (requestError || !stagedPhotoURLString) {
NSError *error = [FBSDKShareError errorWithCode:FBSDKShareOpenGraphErrorCode
message:@"Error staging photo"
underlyingError:requestError];
[self->_delegate sharer:self didFailWithError:error];
} else if (stagingHandler) {
NSMutableDictionary *stagedPhoto = [[NSMutableDictionary alloc] initWithDictionary: @{
@"url": stagedPhotoURLString,
@"user_generated": @(photo.userGenerated),
}];
[FBSDKInternalUtility dictionary:stagedPhoto setObject:photo.caption forKey:@"caption"];
stagingHandler(stagedPhoto);
}
};
[request startWithCompletionHandler:completionHandler];
return YES;
} else {
NSError *error = [FBSDKShareError invalidArgumentErrorWithName:@"photo"
value:photo
message:@"Photos must have an imageURL or image."];
[self->_delegate sharer:self didFailWithError:error];
return NO;
}
}
- (BOOL)_stageValue:(id)value
connection:(FBSDKGraphRequestConnection *)connection
stagingHandler:(void(^)(id stagedValue))stagingHandler
{
if ([value isKindOfClass:[NSString class]] ||
[value isKindOfClass:[NSNumber class]]) {
if (stagingHandler != NULL) {
stagingHandler(value);
}
return YES;
} else if ([value isKindOfClass:[NSURL class]]) {
if (stagingHandler != NULL) {
stagingHandler([(NSURL *)value absoluteString]);
}
return YES;
} else if ([value isKindOfClass:[FBSDKSharePhoto class]]) {
return [self _stagePhoto:(FBSDKSharePhoto *)value connection:connection stagingHandler:stagingHandler];
} else if ([value isKindOfClass:[FBSDKShareOpenGraphObject class]]) {
return [self _stageOpenGraphObject:(FBSDKShareOpenGraphObject *)value
connection:connection
stagingHandler:stagingHandler
completionHandler:NULL];
} else if ([value isKindOfClass:[NSArray class]]) {
return [self _stageArray:(NSArray *)value connection:connection stagingHandler:stagingHandler];
} else {
NSError *error = [FBSDKShareError invalidArgumentErrorWithName:@"value"
value:value
message:@"Invalid value type found in Open Graph object."];
[_delegate sharer:self didFailWithError:error];
return NO;
}
}
- (NSString *)_connection:(FBSDKGraphRequestConnection *)connection
addRequest:(FBSDKGraphRequest *)request
completionHandler:(FBSDKGraphRequestHandler)completionHandler
{
NSUInteger requestCount = [connection.requests count];
NSString *batchEntryName = [[NSString alloc] initWithFormat:@"request_%lu", (unsigned long)requestCount];
[connection addRequest:request completionHandler:completionHandler batchEntryName:batchEntryName];
return batchEntryName;
}
- (BOOL)_addToPendingShareAPI
{
@synchronized(g_pendingFBSDKShareAPI) {
if ([g_pendingFBSDKShareAPI containsObject:self]) {
[FBSDKLogger singleShotLogEntry:FBSDKLoggingBehaviorDeveloperErrors logEntry:@"FBSDKShareAPI did not share video content. Video upload already in progress."];
return NO;
}
[g_pendingFBSDKShareAPI addObject:self];
return YES;
}
}
- (void)_removeFromPendingShareAPI
{
@synchronized(g_pendingFBSDKShareAPI) {
[g_pendingFBSDKShareAPI removeObject:self];
_fileHandle = nil;
#if !TARGET_OS_TV
_assetRepresentation = nil;
#endif
}
}
#pragma mark - FBSDKVideoUploaderDelegate
- (NSData *)videoChunkDataForVideoUploader:(FBSDKVideoUploader *)videoUploader startOffset:(NSUInteger)startOffset endOffset:(NSUInteger)endOffset
{
NSUInteger chunkSize = endOffset - startOffset;
if (_fileHandle) {
[_fileHandle seekToFileOffset:startOffset];
NSData *videoChunkData = [_fileHandle readDataOfLength:chunkSize];
if (videoChunkData == nil || videoChunkData.length != chunkSize) {
return nil;
}
return videoChunkData;
}
#if !TARGET_OS_TV
else if (_assetRepresentation) {
NSMutableData *data = [NSMutableData dataWithLength:chunkSize];
NSError *error;
NSUInteger bufferedLength = [_assetRepresentation getBytes:[data mutableBytes] fromOffset:startOffset length:chunkSize error:&error];
if (bufferedLength != chunkSize || data == nil || error) {
return nil;
}
return data;
}
#endif
return nil;
}
- (void)videoUploader:(FBSDKVideoUploader *)videoUploader didCompleteWithResults:(NSDictionary *)results
{
results = [FBSDKTypeUtility dictionaryValue:results];
NSMutableDictionary *shareResults = [[NSMutableDictionary alloc] init];
[FBSDKInternalUtility dictionary:shareResults setObject:FBSDK_SHARE_RESULT_COMPLETION_GESTURE_VALUE_POST forKey:FBSDK_SHARE_RESULT_COMPLETION_GESTURE_KEY];
[FBSDKInternalUtility dictionary:shareResults setObject:[FBSDKTypeUtility stringValue:results[FBSDK_SHARE_VIDEO_ID]] forKey:FBSDK_SHARE_VIDEO_ID];
[_delegate sharer:self didCompleteWithResults:shareResults];
[self _removeFromPendingShareAPI];
}
- (void)videoUploader:(FBSDKVideoUploader *)videoUploader didFailWithError:(NSError *)error
{
[_delegate sharer:self didFailWithError:error];
[self _removeFromPendingShareAPI];
}
@end
@@ -1,33 +0,0 @@
// 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.
#import <UIKit/UIKit.h>
#import <FBSDKCoreKit/FBSDKButton.h>
#import <FBSDKShareKit/FBSDKSharingButton.h>
/**
A button to share content.
Tapping the receiver will invoke the FBSDKShareDialog with the attached shareContent. If the dialog cannot
be shown, the button will be disabled.
*/
@interface FBSDKShareButton : FBSDKButton <FBSDKSharingButton>
@end
@@ -1,90 +0,0 @@
// 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.
#import "FBSDKShareButton.h"
#import "FBSDKCoreKit+Internal.h"
#import "FBSDKShareDialog.h"
@implementation FBSDKShareButton
{
FBSDKShareDialog *_dialog;
}
#pragma mark - Properties
- (id<FBSDKSharingContent>)shareContent
{
return _dialog.shareContent;
}
- (void)setShareContent:(id<FBSDKSharingContent>)shareContent
{
_dialog.shareContent = shareContent;
[self checkImplicitlyDisabled];
}
#pragma mark - FBSDKButtonImpressionTracking
- (NSDictionary *)analyticsParameters
{
return nil;
}
- (NSString *)impressionTrackingEventName
{
return FBSDKAppEventNameFBSDKShareButtonImpression;
}
- (NSString *)impressionTrackingIdentifier
{
return @"share";
}
#pragma mark - FBSDKButton
- (void)configureButton
{
NSString *title =
NSLocalizedStringWithDefaultValue(@"ShareButton.Share", @"FacebookSDK", [FBSDKInternalUtility bundleForStrings],
@"Share",
@"The label for FBSDKShareButton");
[self configureWithIcon:nil
title:title
backgroundColor:nil
highlightedColor:nil];
[self addTarget:self action:@selector(_share:) forControlEvents:UIControlEventTouchUpInside];
_dialog = [[FBSDKShareDialog alloc] init];
}
- (BOOL)isImplicitlyDisabled
{
return ![_dialog canShow] || ![_dialog validateWithError:NULL];
}
#pragma mark - Helper Methods
- (void)_share:(id)sender
{
[self logTapEventWithEventName:FBSDKAppEventNameFBSDKShareButtonDidTap parameters:[self analyticsParameters]];
[_dialog show];
}
@end
@@ -1,53 +0,0 @@
// 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.
#import <Foundation/Foundation.h>
#import <FBSDKShareKit/FBSDKCameraEffectArguments.h>
#import <FBSDKShareKit/FBSDKCameraEffectTextures.h>
#import <FBSDKShareKit/FBSDKSharingContent.h>
#import <FBSDKShareKit/FBSDKSharingScheme.h>
/**
A model for content to share with a Facebook camera effect.
*/
@interface FBSDKShareCameraEffectContent : NSObject <FBSDKSharingContent, FBSDKSharingScheme>
/**
ID of the camera effect to use.
*/
@property (nonatomic, copy) NSString *effectID;
/**
Arguments for the effect.
*/
@property (nonatomic, copy) FBSDKCameraEffectArguments *effectArguments;
/**
Textures for the effect.
*/
@property (nonatomic, copy) FBSDKCameraEffectTextures *effectTextures;
/**
Compares the receiver to another camera effect content.
@param content The other content
@return YES if the receiver's values are equal to the other content's values; otherwise NO
*/
- (BOOL)isEqualToShareCameraEffectContent:(FBSDKShareCameraEffectContent *)content;
@end
@@ -1,236 +0,0 @@
// 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.
#import "FBSDKShareCameraEffectContent.h"
#import "FBSDKCameraEffectArguments+Internal.h"
#import "FBSDKCameraEffectTextures+Internal.h"
#import "FBSDKCoreKit+Internal.h"
#import "FBSDKHashtag.h"
#import "FBSDKShareUtility.h"
static NSString *const kFBSDKShareCameraEffectContentEffectIDKey = @"effectID";
static NSString *const kFBSDKShareCameraEffectContentEffectArgumentsKey = @"effectArguments";
static NSString *const kFBSDKShareCameraEffectContentEffectTexturesKey = @"effectTextures";
static NSString *const kFBSDKShareCameraEffectContentContentURLKey = @"contentURL";
static NSString *const kFBSDKShareCameraEffectContentHashtagKey = @"hashtag";
static NSString *const kFBSDKShareCameraEffectContentPeopleIDsKey = @"peopleIDs";
static NSString *const kFBSDKShareCameraEffectContentPlaceIDKey = @"placeID";
static NSString *const kFBSDKShareCameraEffectContentRefKey = @"ref";
static NSString *const kFBSDKShareCameraEffectContentPageIDKey = @"pageID";
static NSString *const kFBSDKShareCameraEffectContentUUIDKey = @"uuid";
@implementation FBSDKShareCameraEffectContent
#pragma mark - Properties
@synthesize effectID = _effectID;
@synthesize effectArguments = _effectArguments;
@synthesize effectTextures = _effectTextures;
@synthesize contentURL = _contentURL;
@synthesize hashtag = _hashtag;
@synthesize peopleIDs = _peopleIDs;
@synthesize placeID = _placeID;
@synthesize ref = _ref;
@synthesize pageID = _pageID;
@synthesize shareUUID = _shareUUID;
#pragma mark - Initializer
- (instancetype)init
{
self = [super init];
if (self) {
_shareUUID = [NSUUID UUID].UUIDString;
}
return self;
}
#pragma mark - FBSDKSharingContent
- (void)addToParameters:(NSMutableDictionary<NSString *, id> *)parameters
bridgeOptions:(FBSDKShareBridgeOptions)bridgeOptions
{
[FBSDKInternalUtility dictionary:parameters
setObject:_effectID
forKey:@"effect_id"];
NSString *effectArgumentsJSON;
if (_effectArguments) {
effectArgumentsJSON = [FBSDKInternalUtility JSONStringForObject:[_effectArguments allArguments]
error:NULL
invalidObjectHandler:NULL];
}
[FBSDKInternalUtility dictionary:parameters
setObject:effectArgumentsJSON
forKey:@"effect_arguments"];
NSData *effectTexturesData;
if (_effectTextures) {
// Convert the entire textures dictionary into one NSData, because
// the existing API protocol only allows one value to be put into the pasteboard.
NSDictionary<NSString *, UIImage *> *texturesDict = [_effectTextures allTextures];
NSMutableDictionary<NSString *, NSData *> *texturesDataDict = [NSMutableDictionary dictionaryWithCapacity:texturesDict.count];
[texturesDict enumerateKeysAndObjectsUsingBlock:^(NSString *key, UIImage *img, BOOL *stop) {
// Convert UIImages to NSData, because UIImage is not archivable.
NSData *imageData = UIImagePNGRepresentation(img);
if (imageData) {
[texturesDataDict setObject:imageData forKey:key];
}
}];
effectTexturesData = [NSKeyedArchiver archivedDataWithRootObject:texturesDataDict];
}
[FBSDKInternalUtility dictionary:parameters
setObject:effectTexturesData
forKey:@"effect_textures"];
}
#pragma mark - FBSDKSharingScheme
- (NSString *)schemeForMode:(FBSDKShareDialogMode)mode
{
if ((FBSDKShareDialogModeNative == mode) || (FBSDKShareDialogModeAutomatic == mode)) {
if ([FBSDKInternalUtility isMSQRDPlayerAppInstalled]) {
// If installed, launch MSQRD Player for testing effects.
return FBSDK_CANOPENURL_MSQRD_PLAYER;
}
}
return nil;
}
#pragma mark - FBSDKSharingValidation
- (BOOL)validateWithOptions:(FBSDKShareBridgeOptions)bridgeOptions error:(NSError *__autoreleasing *)errorRef
{
if ([_effectID length] > 0) {
NSCharacterSet* nonDigitCharacters = [[NSCharacterSet decimalDigitCharacterSet] invertedSet];
if ([_effectID rangeOfCharacterFromSet:nonDigitCharacters].location != NSNotFound) {
if (errorRef != NULL) {
*errorRef = [FBSDKError invalidArgumentErrorWithName:@"effectID"
value:_effectID
message:@"Invalid value for effectID, effectID can contain only numerical characters."];
}
return NO;
}
}
return YES;
}
#pragma mark - Equality
- (NSUInteger)hash
{
NSUInteger subhashes[] = {
[_effectID hash],
[_effectArguments hash],
[_effectTextures hash],
[_contentURL hash],
[_hashtag hash],
[_peopleIDs hash],
[_placeID hash],
[_ref hash],
[_pageID hash],
[_shareUUID hash],
};
return [FBSDKMath hashWithIntegerArray:subhashes count:sizeof(subhashes) / sizeof(subhashes[0])];
}
- (BOOL)isEqual:(id)object
{
if (self == object) {
return YES;
}
if (![object isKindOfClass:[FBSDKShareCameraEffectContent class]]) {
return NO;
}
return [self isEqualToShareCameraEffectContent:(FBSDKShareCameraEffectContent *)object];
}
- (BOOL)isEqualToShareCameraEffectContent:(FBSDKShareCameraEffectContent *)content
{
return (content &&
[FBSDKInternalUtility object:_effectID isEqualToObject:content.effectID] &&
[FBSDKInternalUtility object:_effectArguments isEqualToObject:content.effectArguments] &&
[FBSDKInternalUtility object:_effectTextures isEqualToObject:content.effectTextures] &&
[FBSDKInternalUtility object:_contentURL isEqualToObject:content.contentURL] &&
[FBSDKInternalUtility object:_hashtag isEqualToObject:content.hashtag] &&
[FBSDKInternalUtility object:_peopleIDs isEqualToObject:content.peopleIDs] &&
[FBSDKInternalUtility object:_placeID isEqualToObject:content.placeID] &&
[FBSDKInternalUtility object:_ref isEqualToObject:content.ref] &&
[FBSDKInternalUtility object:_shareUUID isEqualToObject:content.shareUUID] &&
[FBSDKInternalUtility object:_pageID isEqualToObject:content.pageID]);
}
#pragma mark - NSCoding
+ (BOOL)supportsSecureCoding
{
return YES;
}
- (id)initWithCoder:(NSCoder *)decoder
{
if ((self = [self init])) {
_effectID = [decoder decodeObjectOfClass:[NSString class] forKey:kFBSDKShareCameraEffectContentEffectIDKey];
_effectArguments = [decoder decodeObjectOfClass:[FBSDKCameraEffectArguments class] forKey:kFBSDKShareCameraEffectContentEffectArgumentsKey];
_effectTextures = [decoder decodeObjectOfClass:[FBSDKCameraEffectTextures class] forKey:kFBSDKShareCameraEffectContentEffectTexturesKey];
_contentURL = [decoder decodeObjectOfClass:[NSURL class] forKey:kFBSDKShareCameraEffectContentContentURLKey];
_hashtag = [decoder decodeObjectOfClass:[FBSDKHashtag class] forKey:kFBSDKShareCameraEffectContentHashtagKey];
_peopleIDs = [decoder decodeObjectOfClass:[NSArray class] forKey:kFBSDKShareCameraEffectContentPeopleIDsKey];
_placeID = [decoder decodeObjectOfClass:[NSString class] forKey:kFBSDKShareCameraEffectContentPlaceIDKey];
_ref = [decoder decodeObjectOfClass:[NSString class] forKey:kFBSDKShareCameraEffectContentRefKey];
_pageID = [decoder decodeObjectOfClass:[NSString class] forKey:kFBSDKShareCameraEffectContentPageIDKey];
_shareUUID = [decoder decodeObjectOfClass:[NSString class] forKey:kFBSDKShareCameraEffectContentUUIDKey];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)encoder
{
[encoder encodeObject:_effectID forKey:kFBSDKShareCameraEffectContentEffectIDKey];
[encoder encodeObject:_effectArguments forKey:kFBSDKShareCameraEffectContentEffectArgumentsKey];
[encoder encodeObject:_effectTextures forKey:kFBSDKShareCameraEffectContentEffectTexturesKey];
[encoder encodeObject:_contentURL forKey:kFBSDKShareCameraEffectContentContentURLKey];
[encoder encodeObject:_hashtag forKey:kFBSDKShareCameraEffectContentHashtagKey];
[encoder encodeObject:_peopleIDs forKey:kFBSDKShareCameraEffectContentPeopleIDsKey];
[encoder encodeObject:_placeID forKey:kFBSDKShareCameraEffectContentPlaceIDKey];
[encoder encodeObject:_ref forKey:kFBSDKShareCameraEffectContentRefKey];
[encoder encodeObject:_pageID forKey:kFBSDKShareCameraEffectContentPageIDKey];
[encoder encodeObject:_shareUUID forKey:kFBSDKShareCameraEffectContentUUIDKey];
}
#pragma mark - NSCopying
- (id)copyWithZone:(NSZone *)zone
{
FBSDKShareCameraEffectContent *copy = [[FBSDKShareCameraEffectContent alloc] init];
copy->_effectID = [_effectID copy];
copy->_effectArguments = [_effectArguments copy];
copy->_effectTextures = [_effectTextures copy];
copy->_contentURL = [_contentURL copy];
copy->_hashtag = [_hashtag copy];
copy->_peopleIDs = [_peopleIDs copy];
copy->_placeID = [_placeID copy];
copy->_ref = [_ref copy];
copy->_pageID = [_pageID copy];
copy->_shareUUID = [_shareUUID copy];
return copy;
}
@end
@@ -1,57 +0,0 @@
// 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.
#import <Foundation/Foundation.h>
#import <FBSDKCoreKit/FBSDKMacros.h>
/**
The error domain for all errors from FBSDKShareKit.
Error codes from the SDK in the range 200-299 are reserved for this domain.
*/
FBSDK_EXTERN NSString *const FBSDKShareErrorDomain;
/**
NS_ENUM(NSInteger, FBSDKShareErrorCode)
Error codes for FBSDKShareErrorDomain.
*/
typedef NS_ENUM(NSInteger, FBSDKShareErrorCode)
{
/**
Reserved.
*/
FBSDKShareReservedErrorCode = 200,
/**
The error code for errors from uploading open graph objects.
*/
FBSDKShareOpenGraphErrorCode,
/**
The error code for when a sharing dialog is not available.
Use the canShare methods to check for this case before calling show.
*/
FBSDKShareDialogNotAvailableErrorCode,
/**
@The error code for unknown errors.
*/
FBSDKShareUnknownErrorCode,
};
@@ -1,24 +0,0 @@
// 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.
#import "FBSDKShareConstants.h"
NSString *const FBSDKShareErrorDomain = @"com.facebook.sdk.share";
NSString *const FBSDKShareOpenGraphKeyErrorKey = @"key";
NSString *const FBSDKShareOpenGraphValueErrorKey = @"value";
@@ -1,54 +0,0 @@
// 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.
#import <UIKit/UIKit.h>
#import <FBSDKShareKit/FBSDKShareDialogMode.h>
#import <FBSDKShareKit/FBSDKSharing.h>
#import <FBSDKShareKit/FBSDKSharingContent.h>
/**
A dialog for sharing content on Facebook.
*/
@interface FBSDKShareDialog : NSObject <FBSDKSharingDialog>
/**
Convenience method to show an FBSDKShareDialog with a fromViewController, content and a delegate.
@param viewController A UIViewController to present the dialog from, if appropriate.
@param content The content to be shared.
@param delegate The receiver's delegate.
*/
+ (instancetype)showFromViewController:(UIViewController *)viewController
withContent:(id<FBSDKSharingContent>)content
delegate:(id<FBSDKSharingDelegate>)delegate;
/**
A UIViewController to present the dialog from.
If not specified, the top most view controller will be automatically determined as best as possible.
*/
@property (nonatomic, weak) UIViewController *fromViewController;
/**
The mode with which to display the dialog.
Defaults to FBSDKShareDialogModeAutomatic, which will automatically choose the best available mode.
*/
@property (nonatomic, assign) FBSDKShareDialogMode mode;
@end
File diff suppressed because it is too large. Load diff
@@ -1,65 +0,0 @@
// 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.
#import <Foundation/Foundation.h>
#import <FBSDKCoreKit/FBSDKMacros.h>
/**
NS_ENUM(NSUInteger, FBSDKShareDialogMode)
Modes for the FBSDKShareDialog.
The automatic mode will progressively check the availability of different modes and open the most
appropriate mode for the dialog that is available.
*/
typedef NS_ENUM(NSUInteger, FBSDKShareDialogMode)
{
/**
Acts with the most appropriate mode that is available.
*/
FBSDKShareDialogModeAutomatic = 0,
/**
@Displays the dialog in the main native Facebook app.
*/
FBSDKShareDialogModeNative,
/**
@Displays the dialog in the iOS integrated share sheet.
*/
FBSDKShareDialogModeShareSheet,
/**
@Displays the dialog in Safari.
*/
FBSDKShareDialogModeBrowser,
/**
@Displays the dialog in a UIWebView within the app.
*/
FBSDKShareDialogModeWeb,
/**
@Displays the feed dialog in Safari.
*/
FBSDKShareDialogModeFeedBrowser,
/**
@Displays the feed dialog in a UIWebView within the app.
*/
FBSDKShareDialogModeFeedWeb,
};
/**
Converts an FBSDKShareDialogMode to an NSString.
*/
FBSDK_EXTERN NSString *NSStringFromFBSDKShareDialogMode(FBSDKShareDialogMode dialogMode);
@@ -1,51 +0,0 @@
// 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.
#import "FBSDKShareDialogMode.h"
#import "FBSDKCoreKit+Internal.h"
NSString *NSStringFromFBSDKShareDialogMode(FBSDKShareDialogMode dialogMode)
{
switch (dialogMode) {
case FBSDKShareDialogModeAutomatic:{
return FBSDKAppEventsDialogShareModeAutomatic;
}
case FBSDKShareDialogModeBrowser:{
return FBSDKAppEventsDialogShareModeBrowser;
}
case FBSDKShareDialogModeNative:{
return FBSDKAppEventsDialogShareModeNative;
}
case FBSDKShareDialogModeShareSheet:{
return FBSDKAppEventsDialogShareModeShareSheet;
}
case FBSDKShareDialogModeWeb:{
return FBSDKAppEventsDialogShareModeWeb;
}
case FBSDKShareDialogModeFeedBrowser: {
return FBSDKAppEventsDialogShareModeFeedBrowser;
}
case FBSDKShareDialogModeFeedWeb:{
return FBSDKAppEventsDialogShareModeFeedWeb;
}
default:{
return FBSDKAppEventsDialogShareModeUnknown;
}
}
}
@@ -1,62 +0,0 @@
// 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.
#import <UIKit/UIKit.h>
#import <FBSDKShareKit/FBSDKHashtag.h>
#import <FBSDKShareKit/FBSDKShareAPI.h>
#import <FBSDKShareKit/FBSDKShareConstants.h>
#import <FBSDKShareKit/FBSDKShareLinkContent.h>
#import <FBSDKShareKit/FBSDKShareMediaContent.h>
#import <FBSDKShareKit/FBSDKShareMessengerActionButton.h>
#import <FBSDKShareKit/FBSDKShareMessengerGenericTemplateContent.h>
#import <FBSDKShareKit/FBSDKShareMessengerGenericTemplateElement.h>
#import <FBSDKShareKit/FBSDKShareMessengerMediaTemplateContent.h>
#import <FBSDKShareKit/FBSDKShareMessengerOpenGraphMusicTemplateContent.h>
#import <FBSDKShareKit/FBSDKShareMessengerURLActionButton.h>
#import <FBSDKShareKit/FBSDKShareOpenGraphAction.h>
#import <FBSDKShareKit/FBSDKShareOpenGraphContent.h>
#import <FBSDKShareKit/FBSDKShareOpenGraphObject.h>
#import <FBSDKShareKit/FBSDKSharePhoto.h>
#import <FBSDKShareKit/FBSDKSharePhotoContent.h>
#import <FBSDKShareKit/FBSDKShareVideo.h>
#import <FBSDKShareKit/FBSDKShareVideoContent.h>
#import <FBSDKShareKit/FBSDKSharing.h>
#import <FBSDKShareKit/FBSDKSharingContent.h>
#if !TARGET_OS_TV
#import <FBSDKShareKit/FBSDKAppGroupAddDialog.h>
#import <FBSDKShareKit/FBSDKAppGroupContent.h>
#import <FBSDKShareKit/FBSDKAppGroupJoinDialog.h>
#import <FBSDKShareKit/FBSDKAppInviteContent.h>
#import <FBSDKShareKit/FBSDKAppInviteDialog.h>
#import <FBSDKShareKit/FBSDKGameRequestContent.h>
#import <FBSDKShareKit/FBSDKGameRequestDialog.h>
#import <FBSDKShareKit/FBSDKLikeButton.h>
#import <FBSDKShareKit/FBSDKLikeControl.h>
#import <FBSDKShareKit/FBSDKLikeObjectType.h>
#import <FBSDKShareKit/FBSDKMessageDialog.h>
#import <FBSDKShareKit/FBSDKShareButton.h>
#import <FBSDKShareKit/FBSDKShareCameraEffectContent.h>
#import <FBSDKShareKit/FBSDKShareDialog.h>
#import <FBSDKShareKit/FBSDKShareDialogMode.h>
#import <FBSDKShareKit/FBSDKSendButton.h>
#else
#import <FBSDKShareKit/FBSDKDeviceShareViewController.h>
#import <FBSDKShareKit/FBSDKDeviceShareButton.h>
#endif
@@ -1,78 +0,0 @@
// 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.
#import <Foundation/Foundation.h>
#import <FBSDKShareKit/FBSDKSharingContent.h>
/**
A model for status and link content to be shared.
*/
@interface FBSDKShareLinkContent : NSObject <FBSDKSharingContent>
/**
The description of the link.
If not specified, this field is automatically populated by information scraped from the contentURL,
typically the title of the page. This value may be discarded for specially handled links (ex: iTunes URLs).
@return The description of the link
@deprecated `contentDescription` is deprecated from Graph API 2.9.
For more information, see https://developers.facebook.com/docs/apps/changelog#v2_9_deprecations.
*/
@property (nonatomic, readonly) NSString *contentDescription
DEPRECATED_MSG_ATTRIBUTE("`contentDescription` is deprecated from Graph API 2.9");
/**
The title to display for this link.
This value may be discarded for specially handled links (ex: iTunes URLs).
@return The link title
@deprecated `contentTitle` is deprecated from Graph API 2.9.
For more information, see https://developers.facebook.com/docs/apps/changelog#v2_9_deprecations
*/
@property (nonatomic, readonly) NSString *contentTitle
DEPRECATED_MSG_ATTRIBUTE("`contentTitle` is deprecated from Graph API 2.9");
/**
The URL of a picture to attach to this content.
@return The network URL of an image
@deprecated `imageURL` is deprecated from Graph API 2.9.
For more information, see https://developers.facebook.com/docs/apps/changelog#v2_9_deprecations
*/
@property (nonatomic, readonly) NSURL *imageURL
DEPRECATED_MSG_ATTRIBUTE("`imageURL` is deprecated from Graph API 2.9");
/**
Some quote text of the link.
If specified, the quote text will render with custom styling on top of the link.
@return The quote text of a link
*/
@property (nonatomic, copy) NSString *quote;
/**
Compares the receiver to another link content.
@param content The other content
@return YES if the receiver's values are equal to the other content's values; otherwise NO
*/
- (BOOL)isEqualToShareLinkContent:(FBSDKShareLinkContent *)content;
@end
@@ -1,228 +0,0 @@
// 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.
#import "FBSDKShareLinkContent+Internal.h"
#import "FBSDKCoreKit+Internal.h"
#import "FBSDKHashtag.h"
#import "FBSDKShareUtility.h"
#define FBSDK_SHARE_STATUS_CONTENT_CONTENT_DESCRIPTION_KEY @"contentDescription"
#define FBSDK_SHARE_STATUS_CONTENT_CONTENT_TITLE_KEY @"contentTitle"
#define FBSDK_SHARE_STATUS_CONTENT_CONTENT_URL_KEY @"contentURL"
#define FBSDK_SHARE_STATUS_CONTENT_HASHTAG_KEY @"hashtag"
#define FBSDK_SHARE_STATUS_CONTENT_IMAGE_URL_KEY @"imageURL"
#define FBSDK_SHARE_STATUS_CONTENT_PEOPLE_IDS_KEY @"peopleIDs"
#define FBSDK_SHARE_STATUS_CONTENT_PLACE_ID_KEY @"placeID"
#define FBSDK_SHARE_STATUS_CONTENT_REF_KEY @"ref"
#define FBSDK_SHARE_STATUS_CONTENT_PAGE_ID_KEY @"pageID"
#define FBSDK_SHARE_STATUS_CONTENT_QUOTE_TEXT_KEY @"quote"
#define FBSDK_SHARE_STATUS_CONTENT_FEED_PARAMETERS_KEY @"feedParameters"
#define FBSDK_SHARE_STATUS_CONTENT_UUID_KEY @"uuid"
@implementation FBSDKShareLinkContent
#pragma mark - Properties
@synthesize contentURL = _contentURL;
@synthesize hashtag = _hashtag;
@synthesize peopleIDs = _peopleIDs;
@synthesize placeID = _placeID;
@synthesize ref = _ref;
@synthesize pageID = _pageID;
@synthesize feedParameters = _feedParameters;
@synthesize quote = _quote;
@synthesize shareUUID = _shareUUID;
#pragma mark - Initializer
- (instancetype)init
{
self = [super init];
if (self) {
_shareUUID = [NSUUID UUID].UUIDString;
}
return self;
}
#pragma mark - Setters
- (void)setPeopleIDs:(NSArray *)peopleIDs
{
[FBSDKShareUtility assertCollection:peopleIDs ofClass:[NSString class] name:@"peopleIDs"];
if (![FBSDKInternalUtility object:_peopleIDs isEqualToObject:peopleIDs]) {
_peopleIDs = [peopleIDs copy];
}
}
- (void)setFeedParameters:(NSDictionary *)feedParameters
{
if (![_feedParameters isEqualToDictionary:feedParameters]) {
_feedParameters = [feedParameters copy];
}
}
#pragma mark - FBSDKSharingContent
- (void)addToParameters:(NSMutableDictionary<NSString *, id> *)parameters
bridgeOptions:(FBSDKShareBridgeOptions)bridgeOptions
{
[FBSDKInternalUtility dictionary:parameters setObject:_contentURL forKey:@"link"];
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[FBSDKInternalUtility dictionary:parameters setObject:_contentTitle forKey:@"name"];
[FBSDKInternalUtility dictionary:parameters setObject:_contentDescription forKey:@"description"];
[FBSDKInternalUtility dictionary:parameters setObject:_imageURL forKey:@"picture"];
#pragma clang diagnostic pop
[FBSDKInternalUtility dictionary:parameters setObject:_quote forKey:@"quote"];
/**
Pass link parameter as "messenger_link" due to versioning requirements for message dialog flow.
We will only use the new share flow we developed if messenger_link is present, not link.
*/
[FBSDKInternalUtility dictionary:parameters setObject:_contentURL forKey:@"messenger_link"];
}
#pragma mark - FBSDKSharingValidation
- (BOOL)validateWithOptions:(FBSDKShareBridgeOptions)bridgeOptions error:(NSError *__autoreleasing *)errorRef
{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
return ([FBSDKShareUtility validateNetworkURL:_contentURL name:@"contentURL" error:errorRef] &&
[FBSDKShareUtility validateNetworkURL:_imageURL name:@"imageURL" error:errorRef]);
#pragma clang diagnostic pop
}
#pragma mark - Equality
- (NSUInteger)hash
{
NSUInteger subhashes[] = {
[_contentDescription hash],
[_contentURL hash],
[_hashtag hash],
[_imageURL hash],
[_peopleIDs hash],
[_placeID hash],
[_ref hash],
[_pageID hash],
[_contentTitle hash],
[_feedParameters hash],
[_quote hash],
[_shareUUID hash],
};
return [FBSDKMath hashWithIntegerArray:subhashes count:sizeof(subhashes) / sizeof(subhashes[0])];
}
- (BOOL)isEqual:(id)object
{
if (self == object) {
return YES;
}
if (![object isKindOfClass:[FBSDKShareLinkContent class]]) {
return NO;
}
return [self isEqualToShareLinkContent:(FBSDKShareLinkContent *)object];
}
- (BOOL)isEqualToShareLinkContent:(FBSDKShareLinkContent *)content
{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
return (content &&
[FBSDKInternalUtility object:_contentDescription isEqualToObject:content.contentDescription] &&
[FBSDKInternalUtility object:_contentTitle isEqualToObject:content.contentTitle] &&
[FBSDKInternalUtility object:_contentURL isEqualToObject:content.contentURL] &&
[FBSDKInternalUtility object:_hashtag isEqualToObject:content.hashtag] &&
[FBSDKInternalUtility object:_feedParameters isEqualToObject:content.feedParameters] &&
[FBSDKInternalUtility object:_imageURL isEqualToObject:content.imageURL] &&
[FBSDKInternalUtility object:_peopleIDs isEqualToObject:content.peopleIDs] &&
[FBSDKInternalUtility object:_placeID isEqualToObject:content.placeID] &&
[FBSDKInternalUtility object:_ref isEqualToObject:content.ref] &&
[FBSDKInternalUtility object:_pageID isEqualToObject:content.pageID] &&
[FBSDKInternalUtility object:_shareUUID isEqualToObject:content.shareUUID]) &&
[FBSDKInternalUtility object:_quote isEqualToObject:content.quote];
#pragma clang diagnostic pop
}
#pragma mark - NSCoding
+ (BOOL)supportsSecureCoding
{
return YES;
}
- (id)initWithCoder:(NSCoder *)decoder
{
if ((self = [self init])) {
_contentDescription = [decoder decodeObjectOfClass:[NSString class]
forKey:FBSDK_SHARE_STATUS_CONTENT_CONTENT_DESCRIPTION_KEY];
_contentTitle = [decoder decodeObjectOfClass:[NSString class] forKey:FBSDK_SHARE_STATUS_CONTENT_CONTENT_TITLE_KEY];
_contentURL = [decoder decodeObjectOfClass:[NSURL class] forKey:FBSDK_SHARE_STATUS_CONTENT_CONTENT_URL_KEY];
_feedParameters = [decoder decodeObjectOfClass:[NSDictionary class] forKey:FBSDK_SHARE_STATUS_CONTENT_FEED_PARAMETERS_KEY];
_hashtag = [decoder decodeObjectOfClass:[FBSDKHashtag class] forKey:FBSDK_SHARE_STATUS_CONTENT_HASHTAG_KEY];
_imageURL = [decoder decodeObjectOfClass:[NSURL class] forKey:FBSDK_SHARE_STATUS_CONTENT_IMAGE_URL_KEY];
_peopleIDs = [decoder decodeObjectOfClass:[NSArray class] forKey:FBSDK_SHARE_STATUS_CONTENT_PEOPLE_IDS_KEY];
_placeID = [decoder decodeObjectOfClass:[NSString class] forKey:FBSDK_SHARE_STATUS_CONTENT_PLACE_ID_KEY];
_ref = [decoder decodeObjectOfClass:[NSString class] forKey:FBSDK_SHARE_STATUS_CONTENT_REF_KEY];
_pageID = [decoder decodeObjectOfClass:[NSString class] forKey:FBSDK_SHARE_STATUS_CONTENT_PAGE_ID_KEY];
_quote = [decoder decodeObjectOfClass:[NSString class] forKey:FBSDK_SHARE_STATUS_CONTENT_QUOTE_TEXT_KEY];
_shareUUID = [decoder decodeObjectOfClass:[NSString class] forKey:FBSDK_SHARE_STATUS_CONTENT_UUID_KEY];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)encoder
{
[encoder encodeObject:_contentDescription forKey:FBSDK_SHARE_STATUS_CONTENT_CONTENT_DESCRIPTION_KEY];
[encoder encodeObject:_contentTitle forKey:FBSDK_SHARE_STATUS_CONTENT_CONTENT_TITLE_KEY];
[encoder encodeObject:_contentURL forKey:FBSDK_SHARE_STATUS_CONTENT_CONTENT_URL_KEY];
[encoder encodeObject:_feedParameters forKey:FBSDK_SHARE_STATUS_CONTENT_FEED_PARAMETERS_KEY];
[encoder encodeObject:_hashtag forKey:FBSDK_SHARE_STATUS_CONTENT_HASHTAG_KEY];
[encoder encodeObject:_imageURL forKey:FBSDK_SHARE_STATUS_CONTENT_IMAGE_URL_KEY];
[encoder encodeObject:_peopleIDs forKey:FBSDK_SHARE_STATUS_CONTENT_PEOPLE_IDS_KEY];
[encoder encodeObject:_placeID forKey:FBSDK_SHARE_STATUS_CONTENT_PLACE_ID_KEY];
[encoder encodeObject:_ref forKey:FBSDK_SHARE_STATUS_CONTENT_REF_KEY];
[encoder encodeObject:_pageID forKey:FBSDK_SHARE_STATUS_CONTENT_PAGE_ID_KEY];
[encoder encodeObject:_quote forKey:FBSDK_SHARE_STATUS_CONTENT_QUOTE_TEXT_KEY];
[encoder encodeObject:_shareUUID forKey:FBSDK_SHARE_STATUS_CONTENT_UUID_KEY];
}
#pragma mark - NSCopying
- (id)copyWithZone:(NSZone *)zone
{
FBSDKShareLinkContent *copy = [[FBSDKShareLinkContent alloc] init];
copy->_contentDescription = [_contentDescription copy];
copy->_contentTitle = [_contentTitle copy];
copy->_contentURL = [_contentURL copy];
copy->_feedParameters = [_feedParameters copy];
copy->_hashtag = [_hashtag copy];
copy->_imageURL = [_imageURL copy];
copy->_peopleIDs = [_peopleIDs copy];
copy->_placeID = [_placeID copy];
copy->_ref = [_ref copy];
copy->_pageID = [_pageID copy];
copy->_quote = [_quote copy];
copy->_shareUUID = [_shareUUID copy];
return copy;
}
@end
@@ -1,41 +0,0 @@
// 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.
#import <Foundation/Foundation.h>
#import <FBSDKShareKit/FBSDKSharingContent.h>
/**
A model for media content (photo or video) to be shared.
*/
@interface FBSDKShareMediaContent : NSObject <FBSDKSharingContent>
/**
Media to be shared.
@return Array of the media (FBSDKSharePhoto or FBSDKShareVideo)
*/
@property (nonatomic, copy) NSArray *media;
/**
Compares the receiver to another media content.
@param content The other content
@return YES if the receiver's values are equal to the other content's values; otherwise NO
*/
- (BOOL)isEqualToShareMediaContent:(FBSDKShareMediaContent *)content;
@end
@@ -1,227 +0,0 @@
// 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.
#import "FBSDKShareMediaContent.h"
#import "FBSDKCoreKit+Internal.h"
#import "FBSDKHashtag.h"
#import "FBSDKShareError.h"
#import "FBSDKSharePhoto.h"
#import "FBSDKShareUtility.h"
#import "FBSDKShareVideo.h"
#define FBSDK_SHARE_MEDIA_CONTENT_CONTENT_URL_KEY @"contentURL"
#define FBSDK_SHARE_MEDIA_CONTENT_HASHTAG_KEY @"hashtag"
#define FBSDK_SHARE_MEDIA_CONTENT_PEOPLE_IDS_KEY @"peopleIDs"
#define FBSDK_SHARE_MEDIA_CONTENT_MEDIA_KEY @"media"
#define FBSDK_SHARE_MEDIA_CONTENT_PLACE_ID_KEY @"placeID"
#define FBSDK_SHARE_MEDIA_CONTENT_REF_KEY @"ref"
#define FBSDK_SHARE_MEDIA_CONTENT_PAGE_ID_KEY @"pageID"
#define FBSDK_SHARE_MEDIA_CONTENT_UUID_KEY @"uuid"
@implementation FBSDKShareMediaContent
#pragma mark - Properties
@synthesize contentURL = _contentURL;
@synthesize hashtag = _hashtag;
@synthesize peopleIDs = _peopleIDs;
@synthesize placeID = _placeID;
@synthesize ref = _ref;
@synthesize pageID = _pageID;
@synthesize shareUUID = _shareUUID;
#pragma mark - Initializer
- (instancetype)init
{
self = [super init];
if (self) {
_shareUUID = [NSUUID UUID].UUIDString;
}
return self;
}
#pragma mark - Setters
- (void)setPeopleIDs:(NSArray *)peopleIDs
{
[FBSDKShareUtility assertCollection:peopleIDs ofClass:[NSString class] name:@"peopleIDs"];
if (![FBSDKInternalUtility object:_peopleIDs isEqualToObject:peopleIDs]) {
_peopleIDs = [peopleIDs copy];
}
}
- (void)setMedia:(NSArray *)media
{
[FBSDKShareUtility assertCollection:media ofClassStrings:@[NSStringFromClass([FBSDKSharePhoto class]), NSStringFromClass([FBSDKShareVideo class])] name:@"media"];
if (![FBSDKInternalUtility object:_media isEqualToObject:media]) {
_media = [media copy];
}
}
#pragma mark - FBSDKSharingContent
- (void)addToParameters:(NSMutableDictionary<NSString *, id> *)parameters
bridgeOptions:(FBSDKShareBridgeOptions)bridgeOptions
{
// FBSDKShareMediaContent is currently available via the Share extension only (thus no parameterization implemented at this time)
}
#pragma mark - FBSDKSharingValidation
- (BOOL)validateWithOptions:(FBSDKShareBridgeOptions)bridgeOptions error:(NSError *__autoreleasing *)errorRef
{
if (![FBSDKShareUtility validateArray:_media minCount:1 maxCount:20 name:@"photos" error:errorRef]) {
return NO;
}
int videoCount = 0;
for (id media in _media) {
if ([media isKindOfClass:[FBSDKSharePhoto class]]) {
FBSDKSharePhoto *photo = (FBSDKSharePhoto *)media;
if (![photo validateWithOptions:bridgeOptions error:NULL]) {
if (errorRef != NULL) {
*errorRef = [FBSDKShareError invalidArgumentErrorWithName:@"media"
value:media
message:@"photos must have UIImages"];
}
return NO;
}
} else if ([media isKindOfClass:[FBSDKShareVideo class]]) {
if (videoCount > 0) {
if (errorRef != NULL) {
*errorRef = [FBSDKShareError invalidArgumentErrorWithName:@"media"
value:media
message:@"Only 1 video is allowed"];
return NO;
}
}
videoCount++;
FBSDKShareVideo *video = (FBSDKShareVideo *)media;
if (![FBSDKShareUtility validateRequiredValue:video name:@"video" error:errorRef]) {
return NO;
}
if (![video validateWithOptions:bridgeOptions error:errorRef]) {
return NO;
}
} else {
if (errorRef != NULL) {
*errorRef = [FBSDKShareError invalidArgumentErrorWithName:@"media"
value:media
message:@"Only FBSDKSharePhoto and FBSDKShareVideo are allowed in `media` property"];
}
return NO;
}
}
return YES;
}
#pragma mark - Equality
- (NSUInteger)hash
{
NSUInteger subhashes[] = {
[_contentURL hash],
[_hashtag hash],
[_peopleIDs hash],
[_media hash],
[_placeID hash],
[_ref hash],
[_pageID hash],
[_shareUUID hash],
};
return [FBSDKMath hashWithIntegerArray:subhashes count:sizeof(subhashes) / sizeof(subhashes[0])];
}
- (BOOL)isEqual:(id)object
{
if (self == object) {
return YES;
}
if (![object isKindOfClass:[FBSDKShareMediaContent class]]) {
return NO;
}
return [self isEqualToShareMediaContent:(FBSDKShareMediaContent *)object];
}
- (BOOL)isEqualToShareMediaContent:(FBSDKShareMediaContent *)content
{
return (content &&
[FBSDKInternalUtility object:_contentURL isEqualToObject:content.contentURL] &&
[FBSDKInternalUtility object:_hashtag isEqualToObject:content.hashtag] &&
[FBSDKInternalUtility object:_peopleIDs isEqualToObject:content.peopleIDs] &&
[FBSDKInternalUtility object:_media isEqualToObject:content.media] &&
[FBSDKInternalUtility object:_placeID isEqualToObject:content.placeID] &&
[FBSDKInternalUtility object:_ref isEqualToObject:content.ref] &&
[FBSDKInternalUtility object:_shareUUID isEqualToObject:content.shareUUID] &&
[FBSDKInternalUtility object:_pageID isEqualToObject:content.pageID]);
}
#pragma mark - NSCoding
+ (BOOL)supportsSecureCoding
{
return YES;
}
- (id)initWithCoder:(NSCoder *)decoder
{
if ((self = [self init])) {
_contentURL = [decoder decodeObjectOfClass:[NSURL class] forKey:FBSDK_SHARE_MEDIA_CONTENT_CONTENT_URL_KEY];
_hashtag = [decoder decodeObjectOfClass:[FBSDKHashtag class] forKey:FBSDK_SHARE_MEDIA_CONTENT_HASHTAG_KEY];
_peopleIDs = [decoder decodeObjectOfClass:[NSArray class] forKey:FBSDK_SHARE_MEDIA_CONTENT_PEOPLE_IDS_KEY];
NSSet *classes = [NSSet setWithObjects:[NSArray class], [FBSDKSharePhoto class], nil];
_media = [decoder decodeObjectOfClasses:classes forKey:FBSDK_SHARE_MEDIA_CONTENT_MEDIA_KEY];
_placeID = [decoder decodeObjectOfClass:[NSString class] forKey:FBSDK_SHARE_MEDIA_CONTENT_PLACE_ID_KEY];
_ref = [decoder decodeObjectOfClass:[NSString class] forKey:FBSDK_SHARE_MEDIA_CONTENT_REF_KEY];
_pageID = [decoder decodeObjectOfClass:[NSString class] forKey:FBSDK_SHARE_MEDIA_CONTENT_PAGE_ID_KEY];
_shareUUID = [decoder decodeObjectOfClass:[NSString class] forKey:FBSDK_SHARE_MEDIA_CONTENT_UUID_KEY];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)encoder
{
[encoder encodeObject:_contentURL forKey:FBSDK_SHARE_MEDIA_CONTENT_CONTENT_URL_KEY];
[encoder encodeObject:_hashtag forKey:FBSDK_SHARE_MEDIA_CONTENT_HASHTAG_KEY];
[encoder encodeObject:_peopleIDs forKey:FBSDK_SHARE_MEDIA_CONTENT_PEOPLE_IDS_KEY];
[encoder encodeObject:_media forKey:FBSDK_SHARE_MEDIA_CONTENT_MEDIA_KEY];
[encoder encodeObject:_placeID forKey:FBSDK_SHARE_MEDIA_CONTENT_PLACE_ID_KEY];
[encoder encodeObject:_ref forKey:FBSDK_SHARE_MEDIA_CONTENT_REF_KEY];
[encoder encodeObject:_pageID forKey:FBSDK_SHARE_MEDIA_CONTENT_PAGE_ID_KEY];
[encoder encodeObject:_shareUUID forKey:FBSDK_SHARE_MEDIA_CONTENT_UUID_KEY];
}
#pragma mark - NSCopying
- (id)copyWithZone:(NSZone *)zone
{
FBSDKShareMediaContent *copy = [[FBSDKShareMediaContent alloc] init];
copy->_contentURL = [_contentURL copy];
copy->_hashtag = [_hashtag copy];
copy->_peopleIDs = [_peopleIDs copy];
copy->_media = [_media copy];
copy->_placeID = [_placeID copy];
copy->_ref = [_ref copy];
copy->_pageID = [_pageID copy];
copy->_shareUUID = [_shareUUID copy];
return copy;
}
@end
@@ -1,34 +0,0 @@
// 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.
#import <Foundation/Foundation.h>
#import <FBSDKCoreKit/FBSDKCopying.h>
/**
A base interface for Messenger share action buttons.
*/
@protocol FBSDKShareMessengerActionButton <FBSDKCopying, NSSecureCoding>
/**
The title displayed to the user for the button.
@return The title for the button.
*/
@property (nonatomic, copy) NSString *title;
@end
@@ -1,55 +0,0 @@
// 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.
#import <Foundation/Foundation.h>
#import <FBSDKShareKit/FBSDKSharingContent.h>
@class FBSDKShareMessengerGenericTemplateElement;
typedef NS_ENUM(NSUInteger, FBSDKShareMessengerGenericTemplateImageAspectRatio) {
FBSDKShareMessengerGenericTemplateImageAspectRatioHorizontal = 0,
FBSDKShareMessengerGenericTemplateImageAspectRatioSquare
};
/**
A model for sharing a generic template element to Messenger. This wrapper element allows
specifying whether or not the bubble is sharable and what aspect to render the images.
See https://developers.facebook.com/docs/messenger-platform/send-messages/template/generic
for more details.
*/
@interface FBSDKShareMessengerGenericTemplateContent : NSObject <FBSDKSharingContent>
/**
This specifies whether or not this generic template message can be shared again after the
initial share. Defaults to false.
*/
@property (nonatomic, assign) BOOL isSharable;
/**
The aspect ratio for when the image is rendered in the generic template bubble after being
shared. Defaults to horizontal.
*/
@property (nonatomic, assign) FBSDKShareMessengerGenericTemplateImageAspectRatio imageAspectRatio;
/**
A generic template element with a title, optional subtitle, optional image, etc. Required.
*/
@property (nonatomic, copy) FBSDKShareMessengerGenericTemplateElement *element;
@end
@@ -1,177 +0,0 @@
// 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.
#import "FBSDKShareMessengerGenericTemplateContent.h"
#import "FBSDKCoreKit+Internal.h"
#import "FBSDKShareMessengerContentUtility.h"
#import "FBSDKShareMessengerGenericTemplateElement.h"
#import "FBSDKShareMessengerURLActionButton.h"
#import "FBSDKShareUtility.h"
static NSString *const kGenericTemplatePageIDKey = @"pageID";
static NSString *const kGenericTemplateUUIDKey = @"UUID";
static NSString *const kGenericTemplateIsSharableKey = @"isSharable";
static NSString *const kGenericTemplateImageAspectRatioKey = @"imageAspectRatio";
static NSString *const kGenericTemplateElementKey = @"element";
static NSString *_ImageAspectRatioString(FBSDKShareMessengerGenericTemplateImageAspectRatio imageAspectRatio)
{
switch (imageAspectRatio) {
case FBSDKShareMessengerGenericTemplateImageAspectRatioSquare:
return @"square";
case FBSDKShareMessengerGenericTemplateImageAspectRatioHorizontal:
return @"horizontal";
}
}
static NSArray<NSDictionary<NSString *, id> *> *_SerializableGenericTemplateElementsFromElements(NSArray<FBSDKShareMessengerGenericTemplateElement *> *elements)
{
NSMutableArray<NSDictionary<NSString *, id> *> *serializableElements = [NSMutableArray array];
for (FBSDKShareMessengerGenericTemplateElement *element in elements) {
NSMutableDictionary<NSString *, id> *elementDictionary = [NSMutableDictionary dictionary];
[FBSDKInternalUtility dictionary:elementDictionary setObject:element.title forKey:@"title"];
[FBSDKInternalUtility dictionary:elementDictionary setObject:element.subtitle forKey:@"subtitle"];
[FBSDKInternalUtility dictionary:elementDictionary setObject:element.imageURL.absoluteString forKey:@"image_url"];
[FBSDKInternalUtility dictionary:elementDictionary setObject:SerializableButtonsFromButton(element.button) forKey:kFBSDKShareMessengerButtonsKey];
if ([element.defaultAction isKindOfClass:[FBSDKShareMessengerURLActionButton class]]) {
[FBSDKInternalUtility dictionary:elementDictionary setObject:SerializableButtonFromURLButton(element.defaultAction, YES) forKey:@"default_action"];
}
[serializableElements addObject:elementDictionary];
}
return serializableElements;
}
@implementation FBSDKShareMessengerGenericTemplateContent
#pragma mark - Properties
@synthesize contentURL = _contentURL;
@synthesize hashtag = _hashtag;
@synthesize peopleIDs = _peopleIDs;
@synthesize placeID = _placeID;
@synthesize ref = _ref;
@synthesize pageID = _pageID;
@synthesize shareUUID = _shareUUID;
#pragma mark - Initializer
- (instancetype)init
{
self = [super init];
if (self) {
_shareUUID = [NSUUID UUID].UUIDString;
}
return self;
}
#pragma mark - FBSDKSharingContent
- (void)addToParameters:(NSMutableDictionary<NSString *, id> *)parameters
bridgeOptions:(FBSDKShareBridgeOptions)bridgeOptions
{
NSMutableDictionary<NSString *, id> *payload = [NSMutableDictionary dictionary];
[payload setObject:@"generic" forKey:kFBSDKShareMessengerTemplateTypeKey];
[payload setObject:@(_isSharable) forKey:@"sharable"];
[payload setObject:_ImageAspectRatioString(_imageAspectRatio) forKey:@"image_aspect_ratio"];
[payload setObject:_SerializableGenericTemplateElementsFromElements(@[_element]) forKey:kFBSDKShareMessengerElementsKey];
NSMutableDictionary<NSString *, id> *attachment = [NSMutableDictionary dictionary];
[attachment setObject:kFBSDKShareMessengerTemplateKey forKey:kFBSDKShareMessengerTypeKey];
[attachment setObject:payload forKey:kFBSDKShareMessengerPayloadKey];
NSMutableDictionary<NSString
*, id> *contentForShare = [NSMutableDictionary dictionary];
[contentForShare setObject:attachment forKey:kFBSDKShareMessengerAttachmentKey];
FBSDKShareMessengerGenericTemplateElement *firstElement = _element;
NSMutableDictionary<NSString *, id> *contentForPreview = [NSMutableDictionary dictionary];
[FBSDKInternalUtility dictionary:contentForPreview setObject:@"DEFAULT" forKey:@"preview_type"];
[FBSDKInternalUtility dictionary:contentForPreview setObject:firstElement.title forKey:@"title"];
[FBSDKInternalUtility dictionary:contentForPreview setObject:firstElement.subtitle forKey:@"subtitle"];
[FBSDKInternalUtility dictionary:contentForPreview setObject:firstElement.imageURL.absoluteString forKey:@"image_url"];
if (firstElement.button) {
AddToContentPreviewDictionaryForButton(contentForPreview, firstElement.button);
} else {
AddToContentPreviewDictionaryForButton(contentForPreview, firstElement.defaultAction);
}
[FBSDKShareMessengerContentUtility addToParameters:parameters contentForShare:contentForShare contentForPreview:contentForPreview];
}
#pragma mark - FBSDKSharingValidation
- (BOOL)validateWithOptions:(FBSDKShareBridgeOptions)bridgeOptions error:(NSError *__autoreleasing *)errorRef
{
return [FBSDKShareUtility validateRequiredValue:_element.title
name:@"element.title"
error:errorRef]
&& [FBSDKShareMessengerContentUtility validateMessengerActionButton:_element.defaultAction
isDefaultActionButton:YES
pageID:_pageID
error:errorRef]
&& [FBSDKShareMessengerContentUtility validateMessengerActionButton:_element.button
isDefaultActionButton:NO
pageID:_pageID
error:errorRef];
}
#pragma mark - NSCoding
+ (BOOL)supportsSecureCoding
{
return YES;
}
- (instancetype)initWithCoder:(NSCoder *)decoder
{
if ((self = [self init])) {
_pageID = [decoder decodeObjectOfClass:[NSString class] forKey:kGenericTemplatePageIDKey];
_isSharable = [decoder decodeBoolForKey:kGenericTemplateIsSharableKey];
_imageAspectRatio = [[decoder decodeObjectOfClass:[NSNumber class] forKey:kGenericTemplateImageAspectRatioKey] unsignedIntegerValue];
_element = [decoder decodeObjectForKey:kGenericTemplateElementKey];
_shareUUID = [decoder decodeObjectOfClass:[NSString class] forKey:kGenericTemplateUUIDKey];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)encoder
{
[encoder encodeObject:_pageID forKey:kGenericTemplatePageIDKey];
[encoder encodeBool:_isSharable forKey:kGenericTemplateIsSharableKey];
[encoder encodeObject:@(_imageAspectRatio) forKey:kGenericTemplateImageAspectRatioKey];
[encoder encodeObject:_element forKey:kGenericTemplateElementKey];
[encoder encodeObject:_shareUUID forKey:kGenericTemplateUUIDKey];
}
#pragma mark - NSCopying
- (id)copyWithZone:(NSZone *)zone
{
FBSDKShareMessengerGenericTemplateContent *copy = [[FBSDKShareMessengerGenericTemplateContent alloc] init];
copy->_pageID = [_pageID copy];
copy->_isSharable = _isSharable;
copy->_imageAspectRatio = _imageAspectRatio;
copy->_element = [_element copy];
copy->_shareUUID = [_shareUUID copy];
return copy;
}
@end
@@ -1,56 +0,0 @@
// 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.
#import <Foundation/Foundation.h>
#import <FBSDKCoreKit/FBSDKCopying.h>
#import <FBSDKShareKit/FBSDKShareMessengerActionButton.h>
/**
A model for sharing a generic template element to Messenger. This allows specifying title, subtitle,
image, default action, and any other buttons. Title is required. See
https://developers.facebook.com/docs/messenger-platform/send-messages/template/generic for more details.
*/
@interface FBSDKShareMessengerGenericTemplateElement : NSObject <FBSDKCopying, NSSecureCoding>
/**
The rendered title for the shared generic template element. Required.
*/
@property (nonatomic, copy) NSString *title;
/**
The rendered subtitle for the shared generic template element. Optional.
*/
@property (nonatomic, copy) NSString *subtitle;
/**
The image url that will be downloaded and rendered at the top of the generic template. Optional.
*/
@property (nonatomic, copy) NSURL *imageURL;
/**
The default action executed when this shared generic tempate is tapped. Title for this button is ignored. Optional.
*/
@property (nonatomic, copy) id<FBSDKShareMessengerActionButton> defaultAction;
/**
This specifies what action button to show below the generic template. Optional.
*/
@property (nonatomic, copy) id<FBSDKShareMessengerActionButton> button;
@end
@@ -1,71 +0,0 @@
// 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.
#import "FBSDKShareMessengerGenericTemplateElement.h"
static NSString *const kGenericTemplateTitleKey = @"title";
static NSString *const kGenericTemplateSubtitleKey = @"subtitle";
static NSString *const kGenericTemplateImageURLKey = @"imageURL";
static NSString *const kGenericTemplateDefaultActionKey = @"defaultAction";
static NSString *const kGenericTemplateButtonKey = @"button";
@implementation FBSDKShareMessengerGenericTemplateElement
#pragma mark - NSCoding
+ (BOOL)supportsSecureCoding
{
return YES;
}
- (instancetype)initWithCoder:(NSCoder *)decoder
{
if ((self = [self init])) {
_title = [decoder decodeObjectOfClass:[NSString class] forKey:kGenericTemplateTitleKey];
_subtitle = [decoder decodeObjectOfClass:[NSString class] forKey:kGenericTemplateSubtitleKey];
_imageURL = [decoder decodeObjectOfClass:[NSURL class] forKey:kGenericTemplateImageURLKey];
_defaultAction = [decoder decodeObjectForKey:kGenericTemplateDefaultActionKey];
_button = [decoder decodeObjectForKey:kGenericTemplateButtonKey];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)encoder
{
[encoder encodeObject:_title forKey:kGenericTemplateTitleKey];
[encoder encodeObject:_subtitle forKey:kGenericTemplateSubtitleKey];
[encoder encodeObject:_imageURL forKey:kGenericTemplateImageURLKey];
[encoder encodeObject:_defaultAction forKey:kGenericTemplateDefaultActionKey];
[encoder encodeObject:_button forKey:kGenericTemplateButtonKey];
}
#pragma mark - NSCopying
- (id)copyWithZone:(NSZone *)zone
{
FBSDKShareMessengerGenericTemplateElement *copy = [[FBSDKShareMessengerGenericTemplateElement alloc] init];
copy->_title = [_title copy];
copy->_subtitle = [_subtitle copy];
copy->_imageURL = [_imageURL copy];
copy->_defaultAction = [_defaultAction copy];
copy->_button = [_button copy];
return copy;
}
@end
@@ -1,69 +0,0 @@
// 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.
#import <Foundation/Foundation.h>
#import <FBSDKShareKit/FBSDKShareMessengerActionButton.h>
#import <FBSDKShareKit/FBSDKSharingContent.h>
typedef NS_ENUM(NSUInteger, FBSDKShareMessengerMediaTemplateMediaType) {
FBSDKShareMessengerMediaTemplateMediaTypeImage = 0,
FBSDKShareMessengerMediaTemplateMediaTypeVideo
};
/**
A model for sharing media template content. See
https://developers.facebook.com/docs/messenger-platform/send-messages/template/media for details.
*/
@interface FBSDKShareMessengerMediaTemplateContent : NSObject <FBSDKSharingContent>
/**
The media type (image or video) for this content. This must match the media type specified in the
attachmentID/mediaURL to avoid an error when sharing. Defaults to image.
*/
@property (nonatomic, assign) FBSDKShareMessengerMediaTemplateMediaType mediaType;
/**
The attachmentID of the item to share. Optional, but either attachmentID or mediaURL must be specified.
*/
@property (nonatomic, copy, readonly) NSString *attachmentID;
/**
The Facebook url for this piece of media. External urls will not work; this must be a Facebook url.
See https://developers.facebook.com/docs/messenger-platform/send-messages/template/media for details.
Optional, but either attachmentID or mediaURL must be specified.
*/
@property (nonatomic, copy, readonly) NSURL *mediaURL;
/**
This specifies what action button to show below the media. Optional.
*/
@property (nonatomic, copy) id<FBSDKShareMessengerActionButton> button;
/**
Custom initializer to create media template share with attachment id.
*/
- (instancetype)initWithAttachmentID:(NSString *)attachmentID;
/**
Custom initializer to create media template share with media url. This must be a Facebook url
and cannot be an external url.
*/
- (instancetype)initWithMediaURL:(NSURL *)mediaURL;
@end
@@ -1,204 +0,0 @@
// 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.
#import "FBSDKShareMessengerMediaTemplateContent.h"
#import "FBSDKCoreKit+Internal.h"
#import "FBSDKHashtag.h"
#import "FBSDKShareError.h"
#import "FBSDKShareMessengerContentUtility.h"
static NSString *const kMediaTemplatePageIDKey = @"pageID";
static NSString *const kMediaTemplateMediaTypeKey = @"mediaType";
static NSString *const kMediaTemplateAttachmentIDKey = @"attachmentID";
static NSString *const kMediaTemplateMediaURLKey = @"mediaURL";
static NSString *const kMediaTemplateButtonKey = @"button";
static NSString *const kMediaTemplateUUIDKey = @"uuid";
static BOOL _URLHasFacebookDomain(NSURL *URL)
{
NSString *urlHost = [URL.host lowercaseString];
NSArray<NSString *> *pathComponents = [URL pathComponents];
/**
Check the following three different cases...
1. Check if host is facebook.com, such as in 'https://facebok.com/test'
2. Check if host is someprefix.facebook.com, such as in 'https://www.facebook.com/test'
3. Check if host is null, but the first path component is facebook.com
*/
return [urlHost isEqualToString:@"facebook.com"] ||
[urlHost hasSuffix:@".facebook.com"] ||
([[[pathComponents firstObject] lowercaseString] hasSuffix:@"facebook.com"]);
}
static NSString *_MediaTemplateURLSerializationKey(NSURL *mediaURL)
{
if (_URLHasFacebookDomain(mediaURL)) {
return @"facebook_media_url";
} else {
return @"image_url";
}
}
static NSString *_MediaTypeString(FBSDKShareMessengerMediaTemplateMediaType mediaType)
{
switch (mediaType) {
case FBSDKShareMessengerMediaTemplateMediaTypeImage:
return @"image";
case FBSDKShareMessengerMediaTemplateMediaTypeVideo:
return @"video";
}
}
static NSArray<NSDictionary<NSString *, id> *> *_SerializableMediaTemplateContentFromContent(FBSDKShareMessengerMediaTemplateContent *mediaTemplateContent)
{
NSMutableArray<NSDictionary<NSString *, id> *> *serializableMediaTemplateContent = [NSMutableArray array];
NSMutableDictionary<NSString *, id> *mediaTemplateContentDictionary = [NSMutableDictionary dictionary];
[FBSDKInternalUtility dictionary:mediaTemplateContentDictionary setObject:_MediaTypeString(mediaTemplateContent.mediaType) forKey:@"media_type"];
[FBSDKInternalUtility dictionary:mediaTemplateContentDictionary setObject:mediaTemplateContent.mediaURL.absoluteString forKey:@"url"];
[FBSDKInternalUtility dictionary:mediaTemplateContentDictionary setObject:mediaTemplateContent.attachmentID forKey:@"attachment_id"];
[FBSDKInternalUtility dictionary:mediaTemplateContentDictionary setObject:SerializableButtonsFromButton(mediaTemplateContent.button) forKey:kFBSDKShareMessengerButtonsKey];
[serializableMediaTemplateContent addObject:mediaTemplateContentDictionary];
return serializableMediaTemplateContent;
}
@implementation FBSDKShareMessengerMediaTemplateContent
#pragma mark - Properties
@synthesize contentURL = _contentURL;
@synthesize hashtag = _hashtag;
@synthesize peopleIDs = _peopleIDs;
@synthesize placeID = _placeID;
@synthesize ref = _ref;
@synthesize pageID = _pageID;
@synthesize shareUUID = _shareUUID;
#pragma mark - Initializer
- (instancetype)initWithAttachmentID:(NSString *)attachmentID
{
self = [super init];
if (self) {
_attachmentID = [attachmentID copy];
_shareUUID = [NSUUID UUID].UUIDString;
}
return self;
}
- (instancetype)initWithMediaURL:(NSURL *)mediaURL
{
self = [super init];
if (self) {
_mediaURL = [mediaURL copy];
_shareUUID = [NSUUID UUID].UUIDString;
}
return self;
}
#pragma mark - FBSDKSharingContent
- (void)addToParameters:(NSMutableDictionary<NSString *, id> *)parameters
bridgeOptions:(FBSDKShareBridgeOptions)bridgeOptions
{
NSMutableDictionary<NSString *, id> *payload = [NSMutableDictionary dictionary];
[payload setObject:@"media" forKey:kFBSDKShareMessengerTemplateTypeKey];
[payload setObject:_SerializableMediaTemplateContentFromContent(self) forKey:kFBSDKShareMessengerElementsKey];
NSMutableDictionary<NSString *, id> *attachment = [NSMutableDictionary dictionary];
[attachment setObject:kFBSDKShareMessengerTemplateKey forKey:kFBSDKShareMessengerTypeKey];
[attachment setObject:payload forKey:kFBSDKShareMessengerPayloadKey];
NSMutableDictionary<NSString *, id> *contentForShare = [NSMutableDictionary dictionary];
[contentForShare setObject:attachment forKey:kFBSDKShareMessengerAttachmentKey];
NSMutableDictionary<NSString *, id> *contentForPreview = [NSMutableDictionary dictionary];
[FBSDKInternalUtility dictionary:contentForPreview setObject:@"DEFAULT" forKey:@"preview_type"];
[FBSDKInternalUtility dictionary:contentForPreview setObject:_attachmentID forKey:@"attachment_id"];
[FBSDKInternalUtility dictionary:contentForPreview
setObject:_mediaURL.absoluteString
forKey:_MediaTemplateURLSerializationKey(_mediaURL)];
[FBSDKInternalUtility dictionary:contentForPreview setObject:_MediaTypeString(_mediaType) forKey:@"media_type"];
AddToContentPreviewDictionaryForButton(contentForPreview, _button);
[FBSDKShareMessengerContentUtility addToParameters:parameters contentForShare:contentForShare contentForPreview:contentForPreview];
}
#pragma mark - FBSDKSharingValidation
- (BOOL)validateWithOptions:(FBSDKShareBridgeOptions)bridgeOptions error:(NSError *__autoreleasing *)errorRef
{
if (!_mediaURL && !_attachmentID) {
if (errorRef != NULL) {
*errorRef = [FBSDKShareError requiredArgumentErrorWithName:@"attachmentID/mediaURL" message:@"Must specify either attachmentID or mediaURL"];
}
return NO;
}
return [FBSDKShareMessengerContentUtility validateMessengerActionButton:_button
isDefaultActionButton:NO
pageID:_pageID
error:errorRef];
}
#pragma mark - NSCoding
+ (BOOL)supportsSecureCoding
{
return YES;
}
- (instancetype)initWithCoder:(NSCoder *)decoder
{
if ((self = [self init])) {
_pageID = [decoder decodeObjectOfClass:[NSString class] forKey:kMediaTemplatePageIDKey];
_mediaType = [[decoder decodeObjectForKey:kMediaTemplateMediaTypeKey] unsignedIntegerValue];
_attachmentID = [decoder decodeObjectOfClass:[NSString class] forKey:kMediaTemplateAttachmentIDKey];
_mediaURL = [decoder decodeObjectOfClass:[NSURL class] forKey:kMediaTemplateMediaURLKey];
_button = [decoder decodeObjectForKey:kMediaTemplateButtonKey];
_shareUUID = [decoder decodeObjectOfClass:[NSString class] forKey:kMediaTemplateUUIDKey];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)encoder
{
[encoder encodeObject:_pageID forKey:kMediaTemplatePageIDKey];
[encoder encodeObject:@(_mediaType) forKey:kMediaTemplateMediaTypeKey];
[encoder encodeObject:_attachmentID forKey:kMediaTemplateAttachmentIDKey];
[encoder encodeObject:_mediaURL forKey:kMediaTemplateMediaURLKey];
[encoder encodeObject:_button forKey:kMediaTemplateButtonKey];
[encoder encodeObject:_shareUUID forKey:kMediaTemplateUUIDKey];
}
#pragma mark - NSCopying
- (id)copyWithZone:(NSZone *)zone
{
FBSDKShareMessengerMediaTemplateContent *copy = [[FBSDKShareMessengerMediaTemplateContent alloc] init];
copy->_pageID = [_pageID copy];
copy->_mediaType = _mediaType;
copy->_attachmentID = [_attachmentID copy];
copy->_mediaURL = [_mediaURL copy];
copy->_button = [_button copy];
copy->_shareUUID = [_shareUUID copy];
return copy;
}
@end
@@ -1,41 +0,0 @@
// 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.
#import <Foundation/Foundation.h>
#import <FBSDKShareKit/FBSDKShareMessengerActionButton.h>
#import <FBSDKShareKit/FBSDKSharingContent.h>
/**
This share content allows sharing a bubble that plays songs with Open Graph music.
See https://developers.facebook.com/docs/messenger-platform/send-messages/template/open-graph
for details. Passing <FBSDKSharingContent> property pageID is required for this type of share.
*/
@interface FBSDKShareMessengerOpenGraphMusicTemplateContent : NSObject <FBSDKSharingContent>
/**
This must be an Open Graph music url. Required.
*/
@property (nonatomic, copy) NSURL *url;
/**
This specifies what action button to show below the open graph music bubble. Optional.
*/
@property (nonatomic, copy) id<FBSDKShareMessengerActionButton> button;
@end
@@ -1,139 +0,0 @@
// 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.
#import "FBSDKShareMessengerOpenGraphMusicTemplateContent.h"
#import "FBSDKCoreKit+Internal.h"
#import "FBSDKShareMessengerContentUtility.h"
#import "FBSDKShareUtility.h"
static NSString *const kMusicTemplatePageIDKey = @"pageID";
static NSString *const kMusicTemplateURLKey = @"url";
static NSString *const kMusicTemplateButtonKey = @"button";
static NSString *const kMusicTemplateUUIDKey = @"uuid";
static NSArray<NSDictionary<NSString *, id> *> *_SerializableOpenGraphMusicTemplateContentFromContent(FBSDKShareMessengerOpenGraphMusicTemplateContent *openGraphMusicTemplateContent)
{
NSMutableArray<NSDictionary<NSString *, id> *> *serializableOpenGraphMusicTemplateContent = [NSMutableArray array];
NSMutableDictionary<NSString *, id> *openGraphMusicTemplateContentDictionary = [NSMutableDictionary dictionary];
[FBSDKInternalUtility dictionary:openGraphMusicTemplateContentDictionary setObject:openGraphMusicTemplateContent.url.absoluteString forKey:@"url"];
[FBSDKInternalUtility dictionary:openGraphMusicTemplateContentDictionary setObject:SerializableButtonsFromButton(openGraphMusicTemplateContent.button) forKey:kFBSDKShareMessengerButtonsKey];
[serializableOpenGraphMusicTemplateContent addObject:openGraphMusicTemplateContentDictionary];
return serializableOpenGraphMusicTemplateContent;
}
@implementation FBSDKShareMessengerOpenGraphMusicTemplateContent
#pragma mark - Properties
@synthesize contentURL = _contentURL;
@synthesize hashtag = _hashtag;
@synthesize peopleIDs = _peopleIDs;
@synthesize placeID = _placeID;
@synthesize ref = _ref;
@synthesize pageID = _pageID;
@synthesize shareUUID = _shareUUID;
#pragma mark - Initializer
- (instancetype)init
{
self = [super init];
if (self) {
_shareUUID = [NSUUID UUID].UUIDString;
}
return self;
}
#pragma mark - FBSDKSharingContent
- (void)addToParameters:(NSMutableDictionary<NSString *, id> *)parameters
bridgeOptions:(FBSDKShareBridgeOptions)bridgeOptions
{
NSMutableDictionary<NSString *, id> *payload = [NSMutableDictionary dictionary];
[payload setObject:@"open_graph" forKey:kFBSDKShareMessengerTemplateTypeKey];
[payload setObject:_SerializableOpenGraphMusicTemplateContentFromContent(self) forKey:kFBSDKShareMessengerElementsKey];
NSMutableDictionary<NSString *, id> *attachment = [NSMutableDictionary dictionary];
[attachment setObject:kFBSDKShareMessengerTemplateKey forKey:kFBSDKShareMessengerTypeKey];
[attachment setObject:payload forKey:kFBSDKShareMessengerPayloadKey];
NSMutableDictionary<NSString *, id> *contentForShare = [NSMutableDictionary dictionary];
[contentForShare setObject:attachment forKey:kFBSDKShareMessengerAttachmentKey];
NSMutableDictionary<NSString *, id> *contentForPreview = [NSMutableDictionary dictionary];
[FBSDKInternalUtility dictionary:contentForPreview setObject:@"OPEN_GRAPH" forKey:@"preview_type"];
[FBSDKInternalUtility dictionary:contentForPreview setObject:_url.absoluteString forKey:@"open_graph_url"];
AddToContentPreviewDictionaryForButton(contentForPreview, _button);
[FBSDKShareMessengerContentUtility addToParameters:parameters contentForShare:contentForShare contentForPreview:contentForPreview];
}
#pragma mark - FBSDKSharingValidation
- (BOOL)validateWithOptions:(FBSDKShareBridgeOptions)bridgeOptions error:(NSError *__autoreleasing *)errorRef
{
return [FBSDKShareUtility validateRequiredValue:_url name:@"url" error:errorRef]
&& [FBSDKShareUtility validateRequiredValue:_pageID name:@"pageID" error:errorRef]
&& [FBSDKShareMessengerContentUtility validateMessengerActionButton:_button
isDefaultActionButton:NO
pageID:_pageID
error:errorRef];
}
#pragma mark - NSCoding
+ (BOOL)supportsSecureCoding
{
return YES;
}
- (instancetype)initWithCoder:(NSCoder *)decoder
{
if ((self = [self init])) {
_pageID = [decoder decodeObjectOfClass:[NSString class] forKey:kMusicTemplatePageIDKey];
_url = [decoder decodeObjectOfClass:[NSURL class] forKey:kMusicTemplateURLKey];
_button = [decoder decodeObjectForKey:kMusicTemplateButtonKey];
_shareUUID = [decoder decodeObjectOfClass:[NSString class] forKey:kMusicTemplateUUIDKey];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)encoder
{
[encoder encodeObject:_pageID forKey:kMusicTemplatePageIDKey];
[encoder encodeObject:_url forKey:kMusicTemplateURLKey];
[encoder encodeObject:_button forKey:kMusicTemplateButtonKey];
[encoder encodeObject:_shareUUID forKey:kMusicTemplateUUIDKey];
}
#pragma mark - NSCopying
- (id)copyWithZone:(NSZone *)zone
{
FBSDKShareMessengerOpenGraphMusicTemplateContent *copy = [[FBSDKShareMessengerOpenGraphMusicTemplateContent alloc] init];
copy->_pageID = [_pageID copy];
copy->_url = [_url copy];
copy->_button = [_button copy];
copy->_shareUUID = [_shareUUID copy];
return copy;
}
@end
@@ -1,62 +0,0 @@
// 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.
#import <Foundation/Foundation.h>
#import <FBSDKShareKit/FBSDKShareMessengerActionButton.h>
typedef NS_ENUM(NSUInteger, FBSDKShareMessengerURLActionButtonWebviewHeightRatio) {
FBSDKShareMessengerURLActionButtonWebviewHeightRatioFull = 0,
FBSDKShareMessengerURLActionButtonWebviewHeightRatioTall,
FBSDKShareMessengerURLActionButtonWebviewHeightRatioCompact
};
/**
A model for a Messenger share URL action button.
*/
@interface FBSDKShareMessengerURLActionButton : NSObject <FBSDKShareMessengerActionButton>
/**
The url that this button should open when tapped. Required.
*/
@property (nonatomic, copy) NSURL *url;
/**
This controls the display height of the webview when shown in the Messenger app. Defaults to Full.
*/
@property (nonatomic, assign) FBSDKShareMessengerURLActionButtonWebviewHeightRatio webviewHeightRatio;
/**
This must be true if the url is a Messenger Extensions url. Defaults to NO.
*/
@property (nonatomic, assign) BOOL isMessengerExtensionURL;
/**
This is a fallback url for a Messenger Extensions enabled button. It is used on clients that do not support
Messenger Extensions. If this is not defined, the url will be used as a fallback. Optional, but ignored
unless isMessengerExtensionURL == YES.
*/
@property (nonatomic, copy) NSURL *fallbackURL;
/**
This controls whether we want to hide the share button in the webview or not. It is useful to hide the share
button when the webview is user-specific and contains sensitive information. Defaults to NO.
*/
@property (nonatomic, assign) BOOL shouldHideWebviewShareButton;
@end
@@ -1,82 +0,0 @@
// 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.
#import "FBSDKShareMessengerURLActionButton.h"
#import "FBSDKCoreKit+Internal.h"
#import "FBSDKShareUtility.h"
static NSString *const kURLActionButtonTitleKey = @"title";
static NSString *const kURLActionButtonURLKey = @"url";
static NSString *const kURLActionButtonWebviewHeightRatioKey = @"webviewHeightRatio";
static NSString *const kURLActionButtonMessengerExtensionsKey = @"messengerExtensions";
static NSString *const kURLActionButtonFallbackURLKey = @"fallbackURL";
static NSString *const kURLActionButtonShouldHideWebviewShareButtonKey = @"shouldHideWebviewShareButton";
@implementation FBSDKShareMessengerURLActionButton
#pragma mark - Properties
@synthesize title = _title;
#pragma mark - NSCoding
+ (BOOL)supportsSecureCoding
{
return YES;
}
- (instancetype)initWithCoder:(NSCoder *)decoder
{
if ((self = [self init])) {
_title = [decoder decodeObjectOfClass:[NSString class] forKey:kURLActionButtonTitleKey];
_url = [decoder decodeObjectOfClass:[NSURL class] forKey:kURLActionButtonURLKey];
_webviewHeightRatio = [[decoder decodeObjectOfClass:[NSNumber class] forKey:kURLActionButtonWebviewHeightRatioKey] unsignedIntegerValue];
_isMessengerExtensionURL = [decoder decodeBoolForKey:kURLActionButtonMessengerExtensionsKey];
_fallbackURL = [decoder decodeObjectOfClass:[NSURL class] forKey:kURLActionButtonFallbackURLKey];
_shouldHideWebviewShareButton = [decoder decodeBoolForKey:kURLActionButtonShouldHideWebviewShareButtonKey];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)encoder
{
[encoder encodeObject:_title forKey:kURLActionButtonTitleKey];
[encoder encodeObject:_url forKey:kURLActionButtonURLKey];
[encoder encodeObject:@(_webviewHeightRatio) forKey:kURLActionButtonWebviewHeightRatioKey];
[encoder encodeBool:_isMessengerExtensionURL forKey:kURLActionButtonMessengerExtensionsKey];
[encoder encodeObject:_fallbackURL forKey:kURLActionButtonFallbackURLKey];
[encoder encodeBool:_shouldHideWebviewShareButton forKey:kURLActionButtonShouldHideWebviewShareButtonKey];
}
#pragma mark - NSCopying
- (id)copyWithZone:(NSZone *)zone
{
FBSDKShareMessengerURLActionButton *copy = [[FBSDKShareMessengerURLActionButton alloc] init];
copy->_title = [_title copy];
copy->_url = [_url copy];
copy->_webviewHeightRatio = _webviewHeightRatio;
copy->_isMessengerExtensionURL = _isMessengerExtensionURL;
copy->_fallbackURL = [_fallbackURL copy];
copy->_shouldHideWebviewShareButton = _shouldHideWebviewShareButton;
return copy;
}
@end
@@ -1,70 +0,0 @@
// 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.
#import <Foundation/Foundation.h>
#import <FBSDKCoreKit/FBSDKCopying.h>
#import <FBSDKShareKit/FBSDKShareOpenGraphObject.h>
#import <FBSDKShareKit/FBSDKShareOpenGraphValueContainer.h>
/**
An Open Graph Action for sharing.
The property keys MUST have namespaces specified on them, such as `og:image`.
*/
@interface FBSDKShareOpenGraphAction : FBSDKShareOpenGraphValueContainer <FBSDKCopying, NSSecureCoding>
/**
Convenience method to build a new action and set the object for the specified key.
@param actionType The action type of the receiver
@param object The Open Graph object represented by this action
@param key The key for the object
*/
+ (instancetype)actionWithType:(NSString *)actionType object:(FBSDKShareOpenGraphObject *)object key:(NSString *)key;
/**
Convenience method to build a new action and set the object for the specified key.
@param actionType The action type of the receiver
@param objectID The ID of an existing Open Graph object
@param key The key for the object
*/
+ (instancetype)actionWithType:(NSString *)actionType objectID:(NSString *)objectID key:(NSString *)key;
/**
Convenience method to build a new action and set the object for the specified key.
@param actionType The action type of the receiver
@param objectURL The URL to a page that defines the Open Graph object with meta tags
@param key The key for the object
*/
+ (instancetype)actionWithType:(NSString *)actionType objectURL:(NSURL *)objectURL key:(NSString *)key;
/**
Gets the action type.
@return The action type
*/
@property (nonatomic, copy) NSString *actionType;
/**
Compares the receiver to another Open Graph Action.
@param action The other action
@return YES if the receiver's values are equal to the other action's values; otherwise NO
*/
- (BOOL)isEqualToShareOpenGraphAction:(FBSDKShareOpenGraphAction *)action;
@end
@@ -1,117 +0,0 @@
// 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.
#import "FBSDKShareOpenGraphAction.h"
#import "FBSDKCoreKit+Internal.h"
#import "FBSDKShareOpenGraphValueContainer+Internal.h"
#define FBSDK_SHARE_OPEN_GRAPH_ACTION_TYPE_KEY @"type"
@implementation FBSDKShareOpenGraphAction
#pragma mark - Class Methods
+ (instancetype)actionWithType:(NSString *)actionType object:(FBSDKShareOpenGraphObject *)object key:(NSString *)key
{
FBSDKShareOpenGraphAction *action = [[FBSDKShareOpenGraphAction alloc] init];
action.actionType = actionType;
[action setObject:object forKey:key];
return action;
}
+ (instancetype)actionWithType:(NSString *)actionType objectID:(NSString *)objectID key:(NSString *)key
{
FBSDKShareOpenGraphAction *action = [[FBSDKShareOpenGraphAction alloc] init];
action.actionType = actionType;
[action setString:objectID forKey:key];
return action;
}
+ (instancetype)actionWithType:(NSString *)actionType objectURL:(NSURL *)objectURL key:(NSString *)key
{
FBSDKShareOpenGraphAction *action = [[FBSDKShareOpenGraphAction alloc] init];
action.actionType = actionType;
[action setURL:objectURL forKey:key];
return action;
}
#pragma mark - Equality
- (NSUInteger)hash
{
return [FBSDKMath hashWithInteger:[super hash] andInteger:[_actionType hash]];
}
- (BOOL)isEqual:(id)object
{
if (self == object) {
return YES;
}
if (![object isKindOfClass:[FBSDKShareOpenGraphAction class]]) {
return NO;
}
return [self isEqualToShareOpenGraphAction:(FBSDKShareOpenGraphAction *)object];
}
- (BOOL)isEqualToShareOpenGraphAction:(FBSDKShareOpenGraphAction *)action
{
return (action &&
[FBSDKInternalUtility object:_actionType isEqualToObject:action.actionType] &&
[self isEqualToShareOpenGraphValueContainer:action]);
}
#pragma mark - NSCoding
+ (BOOL)supportsSecureCoding
{
return YES;
}
- (id)initWithCoder:(NSCoder *)decoder
{
if ((self = [super initWithCoder:decoder])) {
_actionType = [decoder decodeObjectOfClass:[NSString class] forKey:FBSDK_SHARE_OPEN_GRAPH_ACTION_TYPE_KEY];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)encoder
{
[super encodeWithCoder:encoder];
[encoder encodeObject:_actionType forKey:FBSDK_SHARE_OPEN_GRAPH_ACTION_TYPE_KEY];
}
#pragma mark - NSCopying
- (id)copyWithZone:(NSZone *)zone
{
FBSDKShareOpenGraphAction *copy = [[FBSDKShareOpenGraphAction alloc] init];
copy->_actionType = [_actionType copy];
[copy parseProperties:[self allProperties]];
return copy;
}
#pragma mark - Internal Methods
- (BOOL)requireKeyNamespace
{
return NO;
}
@end
@@ -1,50 +0,0 @@
// 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.
#import <Foundation/Foundation.h>
#import <FBSDKShareKit/FBSDKShareOpenGraphAction.h>
#import <FBSDKShareKit/FBSDKSharingContent.h>
/**
A model for Open Graph content to be shared.
*/
@interface FBSDKShareOpenGraphContent : NSObject <FBSDKSharingContent>
/**
Open Graph Action to be shared.
@return The action
*/
@property (nonatomic, copy) FBSDKShareOpenGraphAction *action;
/**
Property name that points to the primary Open Graph Object in the action.
The value that this action points to will be use for rendering the preview for the share.
@return The property name for the Open Graph Object in the action
*/
@property (nonatomic, copy) NSString *previewPropertyName;
/**
Compares the receiver to another Open Graph content.
@param content The other content
@return YES if the receiver's values are equal to the other content's values; otherwise NO
*/
- (BOOL)isEqualToShareOpenGraphContent:(FBSDKShareOpenGraphContent *)content;
@end
@@ -1,191 +0,0 @@
// 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.
#import "FBSDKShareOpenGraphContent.h"
#import "FBSDKCoreKit+Internal.h"
#import "FBSDKHashtag.h"
#import "FBSDKSharePhoto.h"
#import "FBSDKShareUtility.h"
#define FBSDK_SHARE_OPEN_GRAPH_CONTENT_ACTION_KEY @"action"
#define FBSDK_SHARE_OPEN_GRAPH_CONTENT_CONTENT_URL_KEY @"contentURL"
#define FBSDK_SHARE_OPEN_GRAPH_CONTENT_HASHTAG_KEY @"hashtag"
#define FBSDK_SHARE_OPEN_GRAPH_CONTENT_PEOPLE_IDS_KEY @"peopleIDs"
#define FBSDK_SHARE_OPEN_GRAPH_CONTENT_PLACE_ID_KEY @"placeID"
#define FBSDK_SHARE_OPEN_GRAPH_CONTENT_PREVIEW_PROPERTY_NAME_KEY @"previewPropertyName"
#define FBSDK_SHARE_OPEN_GRAPH_CONTENT_REF_KEY @"ref"
#define FBSDK_SHARE_OPEN_GRAPH_CONTENT_PAGE_ID_KEY @"pageID"
#define FBSDK_SHARE_OPEN_GRAPH_CONTENT_UUID_KEY @"uuid"
@implementation FBSDKShareOpenGraphContent
#pragma mark - Properties
@synthesize contentURL = _contentURL;
@synthesize hashtag = _hashtag;
@synthesize peopleIDs = _peopleIDs;
@synthesize placeID = _placeID;
@synthesize ref = _ref;
@synthesize pageID = _pageID;
@synthesize shareUUID = _shareUUID;
#pragma mark - Initializer
- (instancetype)init
{
self = [super init];
if (self) {
_shareUUID = [NSUUID UUID].UUIDString;
}
return self;
}
#pragma mark - Setters
- (void)setPeopleIDs:(NSArray *)peopleIDs
{
[FBSDKShareUtility assertCollection:peopleIDs ofClass:[NSString class] name:@"peopleIDs"];
if (![FBSDKInternalUtility object:_peopleIDs isEqualToObject:peopleIDs]) {
_peopleIDs = [peopleIDs copy];
}
}
#pragma mark - FBSDKSharingContent
- (void)addToParameters:(NSMutableDictionary<NSString *, id> *)parameters
bridgeOptions:(FBSDKShareBridgeOptions)bridgeOptions
{
NSString *previewPropertyName = [FBSDKShareUtility getOpenGraphNameAndNamespaceFromFullName:_previewPropertyName namespace:nil];
[FBSDKInternalUtility dictionary:parameters
setObject:previewPropertyName
forKey:@"previewPropertyName"];
[FBSDKInternalUtility dictionary:parameters setObject:_action.actionType forKey:@"actionType"];
[FBSDKInternalUtility dictionary:parameters
setObject:[FBSDKShareUtility convertOpenGraphValueContainer:_action requireNamespace:NO]
forKey:@"action"];
}
#pragma mark - FBSDKSharingValidation
- (BOOL)validateWithOptions:(FBSDKShareBridgeOptions)bridgeOptions error:(NSError *__autoreleasing *)errorRef
{
return ([FBSDKShareUtility validateRequiredValue:_action name:@"action" error:errorRef] &&
[FBSDKShareUtility validateRequiredValue:_previewPropertyName name:@"previewPropertyName" error:errorRef] &&
[FBSDKShareUtility validateRequiredValue:_action[_previewPropertyName] name:_previewPropertyName error:errorRef]);
}
#pragma mark - Equality
- (NSUInteger)hash
{
NSUInteger subhashes[] = {
[_action hash],
[_contentURL hash],
[_hashtag hash],
[_peopleIDs hash],
[_placeID hash],
[_previewPropertyName hash],
[_ref hash],
[_pageID hash],
[_shareUUID hash],
};
return [FBSDKMath hashWithIntegerArray:subhashes count:sizeof(subhashes) / sizeof(subhashes[0])];
}
- (BOOL)isEqual:(id)object
{
if (self == object) {
return YES;
}
if (![object isKindOfClass:[FBSDKShareOpenGraphContent class]]) {
return NO;
}
return [self isEqualToShareOpenGraphContent:(FBSDKShareOpenGraphContent *)object];
}
- (BOOL)isEqualToShareOpenGraphContent:(FBSDKShareOpenGraphContent *)content
{
return (content &&
[FBSDKInternalUtility object:_action isEqualToObject:content.action] &&
[FBSDKInternalUtility object:_contentURL isEqualToObject:content.contentURL] &&
[FBSDKInternalUtility object:_hashtag isEqualToObject:content.hashtag] &&
[FBSDKInternalUtility object:_peopleIDs isEqualToObject:content.peopleIDs] &&
[FBSDKInternalUtility object:_placeID isEqualToObject:content.placeID] &&
[FBSDKInternalUtility object:_previewPropertyName isEqualToObject:content.previewPropertyName] &&
[FBSDKInternalUtility object:_ref isEqualToObject:content.ref] &&
[FBSDKInternalUtility object:_shareUUID isEqualToObject:content.shareUUID] &&
[FBSDKInternalUtility object:_pageID isEqualToObject:content.pageID]);
}
#pragma mark - NSCoding
+ (BOOL)supportsSecureCoding
{
return YES;
}
- (id)initWithCoder:(NSCoder *)decoder
{
if ((self = [super init])) {
_action = [decoder decodeObjectOfClass:[FBSDKShareOpenGraphAction class]
forKey:FBSDK_SHARE_OPEN_GRAPH_CONTENT_ACTION_KEY];
_contentURL = [decoder decodeObjectOfClass:[NSURL class] forKey:FBSDK_SHARE_OPEN_GRAPH_CONTENT_CONTENT_URL_KEY];
_hashtag = [decoder decodeObjectOfClass:[FBSDKHashtag class] forKey:FBSDK_SHARE_OPEN_GRAPH_CONTENT_HASHTAG_KEY];
_peopleIDs = [decoder decodeObjectOfClass:[NSArray class] forKey:FBSDK_SHARE_OPEN_GRAPH_CONTENT_PEOPLE_IDS_KEY];
_placeID = [decoder decodeObjectOfClass:[NSString class] forKey:FBSDK_SHARE_OPEN_GRAPH_CONTENT_PLACE_ID_KEY];
_previewPropertyName = [decoder decodeObjectOfClass:[NSString class]
forKey:FBSDK_SHARE_OPEN_GRAPH_CONTENT_PREVIEW_PROPERTY_NAME_KEY];
_ref = [decoder decodeObjectOfClass:[NSString class] forKey:FBSDK_SHARE_OPEN_GRAPH_CONTENT_REF_KEY];
_pageID = [decoder decodeObjectOfClass:[NSString class] forKey:FBSDK_SHARE_OPEN_GRAPH_CONTENT_PAGE_ID_KEY];
_shareUUID = [decoder decodeObjectOfClass:[NSString class] forKey:FBSDK_SHARE_OPEN_GRAPH_CONTENT_UUID_KEY];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)encoder
{
[encoder encodeObject:_action forKey:FBSDK_SHARE_OPEN_GRAPH_CONTENT_ACTION_KEY];
[encoder encodeObject:_contentURL forKey:FBSDK_SHARE_OPEN_GRAPH_CONTENT_CONTENT_URL_KEY];
[encoder encodeObject:_hashtag forKey:FBSDK_SHARE_OPEN_GRAPH_CONTENT_HASHTAG_KEY];
[encoder encodeObject:_peopleIDs forKey:FBSDK_SHARE_OPEN_GRAPH_CONTENT_PEOPLE_IDS_KEY];
[encoder encodeObject:_placeID forKey:FBSDK_SHARE_OPEN_GRAPH_CONTENT_PLACE_ID_KEY];
[encoder encodeObject:_previewPropertyName forKey:FBSDK_SHARE_OPEN_GRAPH_CONTENT_PREVIEW_PROPERTY_NAME_KEY];
[encoder encodeObject:_ref forKey:FBSDK_SHARE_OPEN_GRAPH_CONTENT_REF_KEY];
[encoder encodeObject:_pageID forKey:FBSDK_SHARE_OPEN_GRAPH_CONTENT_PAGE_ID_KEY];
[encoder encodeObject:_shareUUID forKey:FBSDK_SHARE_OPEN_GRAPH_CONTENT_UUID_KEY];
}
#pragma mark - NSCopying
- (id)copyWithZone:(NSZone *)zone
{
FBSDKShareOpenGraphContent *copy = [[FBSDKShareOpenGraphContent alloc] init];
copy->_action = [_action copy];
copy->_contentURL = [_contentURL copy];
copy->_hashtag = [_hashtag copy];
copy->_peopleIDs = [_peopleIDs copy];
copy->_placeID = [_placeID copy];
copy->_previewPropertyName = [_previewPropertyName copy];
copy->_ref = [_ref copy];
copy->_pageID = [_pageID copy];
copy->_shareUUID = [_shareUUID copy];
return copy;
}
@end
@@ -1,59 +0,0 @@
// 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.
#import <Foundation/Foundation.h>
#import <FBSDKCoreKit/FBSDKCopying.h>
#import <FBSDKShareKit/FBSDKShareOpenGraphValueContainer.h>
/**
An Open Graph Object for sharing.
The property keys MUST have namespaces specified on them, such as `og:image`,
and `og:type` is required.
See https://developers.facebook.com/docs/sharing/opengraph/object-properties for other properties.
You can specify nested namespaces inline to define complex properties. For example, the following
code will generate a fitness.course object with a location:
FBSDKShareOpenGraphObject *course = [FBSDKShareOpenGraphObject objectWithProperties:
@{
@"og:type": @"fitness.course",
@"og:title": @"Sample course",
@"fitness:metrics:location:latitude": @"41.40338",
@"fitness:metrics:location:longitude": @"2.17403",
}];
*/
@interface FBSDKShareOpenGraphObject : FBSDKShareOpenGraphValueContainer <FBSDKCopying, NSSecureCoding>
/**
Convenience method to build a new action and set the object for the specified key.
@param properties Properties for the Open Graph object, which will be parsed into the proper models
*/
+ (instancetype)objectWithProperties:(NSDictionary *)properties;
/**
Compares the receiver to another Open Graph Object.
@param object The other object
@return YES if the receiver's values are equal to the other object's values; otherwise NO
*/
- (BOOL)isEqualToShareOpenGraphObject:(FBSDKShareOpenGraphObject *)object;
@end
@@ -1,63 +0,0 @@
// 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.
#import "FBSDKShareOpenGraphObject.h"
#import "FBSDKShareOpenGraphValueContainer+Internal.h"
#define FBSDK_SHARE_OPEN_GRAPH_OBJECT_DATA_KEY @"data"
@implementation FBSDKShareOpenGraphObject
#pragma mark - Class Methods
+ (instancetype)objectWithProperties:(NSDictionary *)properties
{
FBSDKShareOpenGraphObject *object = [[FBSDKShareOpenGraphObject alloc] init];
[object parseProperties:properties];
return object;
}
#pragma mark - Equality
- (BOOL)isEqual:(id)object
{
if (self == object) {
return YES;
}
if (![object isKindOfClass:[FBSDKShareOpenGraphObject class]]) {
return NO;
}
return [self isEqualToShareOpenGraphObject:(FBSDKShareOpenGraphObject *)object];
}
- (BOOL)isEqualToShareOpenGraphObject:(FBSDKShareOpenGraphObject *)object
{
return [self isEqualToShareOpenGraphValueContainer:object];
}
#pragma mark - NSCopying
- (id)copyWithZone:(NSZone *)zone
{
FBSDKShareOpenGraphObject *copy = [[FBSDKShareOpenGraphObject alloc] init];
[copy parseProperties:[self allProperties]];
return copy;
}
@end
@@ -1,162 +0,0 @@
// 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.
#import <Foundation/Foundation.h>
@class FBSDKShareOpenGraphObject;
@class FBSDKSharePhoto;
/**
Protocol defining operations on open graph actions and objects.
The property keys MUST have namespaces specified on them, such as `og:image`.
*/
@protocol FBSDKShareOpenGraphValueContaining <NSObject, NSSecureCoding>
/**
Gets an NSArray out of the receiver.
@param key The key for the value
@return The NSArray value or nil
*/
- (NSArray *)arrayForKey:(NSString *)key;
/**
Applies a given block object to the entries of the receiver.
@param block A block object to operate on entries in the receiver
*/
- (void)enumerateKeysAndObjectsUsingBlock:(void (^)(NSString *key, id object, BOOL *stop))block;
/**
Returns an enumerator object that lets you access each key in the receiver.
@return An enumerator object that lets you access each key in the receiver
*/
- (NSEnumerator *)keyEnumerator;
/**
Gets an NSNumber out of the receiver.
@param key The key for the value
@return The NSNumber value or nil
*/
- (NSNumber *)numberForKey:(NSString *)key;
/**
Returns an enumerator object that lets you access each value in the receiver.
@return An enumerator object that lets you access each value in the receiver
*/
- (NSEnumerator *)objectEnumerator;
/**
Gets an FBSDKShareOpenGraphObject out of the receiver.
@param key The key for the value
@return The FBSDKShareOpenGraphObject value or nil
*/
- (FBSDKShareOpenGraphObject *)objectForKey:(NSString *)key;
/**
Enables subscript access to the values in the receiver.
@param key The key for the value
@return The value
*/
- (id)objectForKeyedSubscript:(NSString *)key;
/**
Parses properties out of a dictionary into the receiver.
@param properties The properties to parse.
*/
- (void)parseProperties:(NSDictionary *)properties;
/**
Gets an FBSDKSharePhoto out of the receiver.
@param key The key for the value
@return The FBSDKSharePhoto value or nil
*/
- (FBSDKSharePhoto *)photoForKey:(NSString *)key;
/**
Removes a value from the receiver for the specified key.
@param key The key for the value
*/
- (void)removeObjectForKey:(NSString *)key;
/**
Sets an NSArray on the receiver.
This method will throw if the array contains any values that is not an NSNumber, NSString, NSURL,
FBSDKSharePhoto or FBSDKShareOpenGraphObject.
@param array The NSArray value
@param key The key for the value
*/
- (void)setArray:(NSArray *)array forKey:(NSString *)key;
/**
Sets an NSNumber on the receiver.
@param number The NSNumber value
@param key The key for the value
*/
- (void)setNumber:(NSNumber *)number forKey:(NSString *)key;
/**
Sets an FBSDKShareOpenGraphObject on the receiver.
@param object The FBSDKShareOpenGraphObject value
@param key The key for the value
*/
- (void)setObject:(FBSDKShareOpenGraphObject *)object forKey:(NSString *)key;
/**
Sets an FBSDKSharePhoto on the receiver.
@param photo The FBSDKSharePhoto value
@param key The key for the value
*/
- (void)setPhoto:(FBSDKSharePhoto *)photo forKey:(NSString *)key;
/**
Sets an NSString on the receiver.
@param string The NSString value
@param key The key for the value
*/
- (void)setString:(NSString *)string forKey:(NSString *)key;
/**
Sets an NSURL on the receiver.
@param URL The NSURL value
@param key The key for the value
*/
- (void)setURL:(NSURL *)URL forKey:(NSString *)key;
/**
Gets an NSString out of the receiver.
@param key The key for the value
@return The NSString value or nil
*/
- (NSString *)stringForKey:(NSString *)key;
/**
Gets an NSURL out of the receiver.
@param key The key for the value
@return The NSURL value or nil
*/
- (NSURL *)URLForKey:(NSString *)key;
@end
/**
A base class to container Open Graph values.
*/
@interface FBSDKShareOpenGraphValueContainer : NSObject <FBSDKShareOpenGraphValueContaining>
@end
@@ -1,238 +0,0 @@
// 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.
#import "FBSDKShareOpenGraphValueContainer.h"
#import "FBSDKShareOpenGraphValueContainer+Internal.h"
#import <FBSDKCoreKit/FBSDKMacros.h>
#import "FBSDKCoreKit+Internal.h"
#import "FBSDKShareOpenGraphObject.h"
#import "FBSDKSharePhoto.h"
#import "FBSDKShareUtility.h"
#define FBSDK_SHARE_OPEN_GRAPH_VALUE_CONTAINER_PROPERTIES_KEY @"properties"
@implementation FBSDKShareOpenGraphValueContainer
{
NSMutableDictionary *_properties;
}
#pragma mark - Object Lifecycle
- (instancetype)init
{
if ((self = [super init])) {
_properties = [[NSMutableDictionary alloc] init];
}
return self;
}
#pragma mark - Public Methods
- (NSDictionary *)allData
{
return [_properties copy];
}
- (NSArray *)arrayForKey:(NSString *)key
{
return [self _valueOfClass:[NSArray class] forKey:key];
}
- (void)enumerateKeysAndObjectsUsingBlock:(void (^)(NSString *key, id object, BOOL *stop))block
{
[_properties enumerateKeysAndObjectsUsingBlock:block];
}
- (NSEnumerator *)keyEnumerator
{
return [_properties keyEnumerator];
}
- (NSNumber *)numberForKey:(NSString *)key
{
return [self _valueOfClass:[NSNumber class] forKey:key];
}
- (NSEnumerator *)objectEnumerator
{
return [_properties objectEnumerator];
}
- (FBSDKShareOpenGraphObject *)objectForKey:(NSString *)key
{
return [self _valueOfClass:[FBSDKShareOpenGraphObject class] forKey:key];
}
- (id)objectForKeyedSubscript:(id<NSCopying>)key
{
return [self _valueForKey:key];
}
- (void)parseProperties:(NSDictionary *)properties
{
[FBSDKShareUtility assertOpenGraphValues:properties requireKeyNamespace:[self requireKeyNamespace]];
[_properties addEntriesFromDictionary:[FBSDKShareUtility convertOpenGraphValues:properties]];
}
- (FBSDKSharePhoto *)photoForKey:(NSString *)key
{
return [self _valueOfClass:[FBSDKSharePhoto class] forKey:key];
}
- (void)removeObjectForKey:(NSString *)key
{
[_properties removeObjectForKey:key];
}
- (void)setArray:(NSArray *)array forKey:(NSString *)key
{
[self _setValue:array forKey:key];
}
- (void)setNumber:(NSNumber *)number forKey:(NSString *)key
{
[self _setValue:number forKey:key];
}
- (void)setObject:(FBSDKShareOpenGraphObject *)object forKey:(NSString *)key
{
[self _setValue:object forKey:key];
}
- (void)setPhoto:(FBSDKSharePhoto *)photo forKey:(NSString *)key
{
[self _setValue:photo forKey:key];
}
- (void)setString:(NSString *)string forKey:(NSString *)key
{
[self _setValue:string forKey:key];
}
- (void)setURL:(NSURL *)URL forKey:(NSString *)key
{
[self _setValue:URL forKey:key];
}
- (NSString *)stringForKey:(NSString *)key
{
return [self _valueOfClass:[NSString class] forKey:key];
}
- (NSURL *)URLForKey:(NSString *)key
{
return [self _valueOfClass:[NSURL class] forKey:key];
}
- (id)valueForKey:(NSString *)key
{
return [self _valueForKey:key] ?: [super valueForKey:key];
}
#pragma mark - Internal Methods
- (NSDictionary *)allProperties
{
return _properties;
}
- (BOOL)requireKeyNamespace
{
return YES;
}
#pragma mark - Equality
- (NSUInteger)hash
{
return [_properties hash];
}
- (BOOL)isEqual:(id)object
{
if (self == object) {
return YES;
}
if (![object isKindOfClass:[FBSDKShareOpenGraphValueContainer class]]) {
return NO;
}
return [self isEqualToShareOpenGraphValueContainer:(FBSDKShareOpenGraphValueContainer *)object];
}
- (BOOL)isEqualToShareOpenGraphValueContainer:(FBSDKShareOpenGraphValueContainer *)object
{
return [FBSDKInternalUtility object:_properties isEqualToObject:[object allProperties]];
}
#pragma mark - NSCoding
+ (BOOL)supportsSecureCoding
{
return YES;
}
- (id)initWithCoder:(NSCoder *)decoder
{
if ((self = [self init])) {
NSSet *classes = [NSSet setWithObjects:
[NSArray class],
[NSDictionary class],
[FBSDKShareOpenGraphObject class],
[FBSDKSharePhoto class],
nil];
NSDictionary *properties = [decoder decodeObjectOfClasses:classes
forKey:FBSDK_SHARE_OPEN_GRAPH_VALUE_CONTAINER_PROPERTIES_KEY];
if ([properties count]) {
[self parseProperties:properties];
}
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)encoder
{
[encoder encodeObject:_properties forKey:FBSDK_SHARE_OPEN_GRAPH_VALUE_CONTAINER_PROPERTIES_KEY];
}
#pragma mark - Helper Methods
- (void)_setValue:(id)value forKey:(NSString *)key
{
[FBSDKShareUtility assertOpenGraphKey:key requireNamespace:[self requireKeyNamespace]];
[FBSDKShareUtility assertOpenGraphValue:value];
if (value) {
_properties[key] = value;
} else {
[self removeObjectForKey:key];
}
}
- (id)_valueForKey:(id)key
{
key = [FBSDKTypeUtility stringValue:key];
return (key ? [FBSDKTypeUtility objectValue:_properties[key]] : nil);
}
- (id)_valueOfClass:(__unsafe_unretained Class)cls forKey:(NSString *)key
{
id value = [self _valueForKey:key];
return ([value isKindOfClass:cls] ? value : nil);
}
@end
@@ -1,98 +0,0 @@
// 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.
#import <UIKit/UIKit.h>
#import <FBSDKCoreKit/FBSDKCopying.h>
#import <FBSDKShareKit/FBSDKSharingValidation.h>
@class PHAsset;
/**
A photo for sharing.
*/
@interface FBSDKSharePhoto : NSObject <FBSDKCopying, FBSDKSharingValidation, NSSecureCoding>
/**
Convenience method to build a new photo object with an image.
@param image If the photo is resident in memory, this method supplies the data
@param userGenerated Specifies whether the photo represented by the receiver was generated by the user or by the
application
*/
+ (instancetype)photoWithImage:(UIImage *)image userGenerated:(BOOL)userGenerated;
/**
Convenience method to build a new photo object with an imageURL.
@param imageURL The URL to the photo
@param userGenerated Specifies whether the photo represented by the receiver was generated by the user or by the
application
This method should only be used when adding photo content to open graph stories.
For example, if you're trying to share a photo from the web by itself, download the image and use
`photoWithImage:userGenerated:` instead.
*/
+ (instancetype)photoWithImageURL:(NSURL *)imageURL userGenerated:(BOOL)userGenerated;
/**
Convenience method to build a new photo object with a PHAsset.
- Parameter photoAsset: The PHAsset that represents the photo in the Photos library.
- Parameter userGenerated: Specifies whether the photo represented by the receiver was generated by the user or by the
application
*/
+ (instancetype)photoWithPhotoAsset:(PHAsset *)photoAsset userGenerated:(BOOL)userGenerated;
/**
If the photo is resident in memory, this method supplies the data.
@return UIImage representation of the photo
*/
@property (nonatomic, strong) UIImage *image;
/**
The URL to the photo.
@return URL that points to a network location or the location of the photo on disk
*/
@property (nonatomic, copy) NSURL *imageURL;
/**
The representation of the photo in the Photos library.
- Returns: PHAsset that represents the photo in the Photos library.
*/
@property (nonatomic, copy) PHAsset *photoAsset;
/**
Specifies whether the photo represented by the receiver was generated by the user or by the application.
@return YES if the photo is user-generated, otherwise NO
*/
@property (nonatomic, assign, getter=isUserGenerated) BOOL userGenerated;
/**
Compares the receiver to another photo.
@param photo The other photo
@return YES if the receiver's values are equal to the other photo's values; otherwise NO
*/
- (BOOL)isEqualToSharePhoto:(FBSDKSharePhoto *)photo;
/**
The user generated caption for the photo. Note that the 'caption' must come from
* the user, as pre-filled content is forbidden by the Platform Policies (2.3).
@return the Photo's caption if exists else returns null.
*/
@property (nonatomic, copy) NSString *caption;
@end
@@ -1,224 +0,0 @@
// 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.
#import "FBSDKSharePhoto.h"
#import <Photos/Photos.h>
#import "FBSDKCoreKit+Internal.h"
#import "FBSDKShareError.h"
NSString *const kFBSDKSharePhotoAssetKey = @"photoAsset";
NSString *const kFBSDKSharePhotoImageKey = @"image";
NSString *const kFBSDKSharePhotoImageURLKey = @"imageURL";
NSString *const kFBSDKSharePhotoUserGeneratedKey = @"userGenerated";
NSString *const kFBSDKSharePhotoCaptionKey = @"caption";
@implementation FBSDKSharePhoto
#pragma mark - Class Methods
+ (instancetype)photoWithImage:(UIImage *)image userGenerated:(BOOL)userGenerated
{
FBSDKSharePhoto *photo = [[self alloc] init];
photo.image = image;
photo.userGenerated = userGenerated;
return photo;
}
+ (instancetype)photoWithImageURL:(NSURL *)imageURL userGenerated:(BOOL)userGenerated
{
FBSDKSharePhoto *photo = [[self alloc] init];
photo.imageURL = imageURL;
photo.userGenerated = userGenerated;
return photo;
}
+ (instancetype)photoWithPhotoAsset:(PHAsset *)photoAsset userGenerated:(BOOL)userGenerated
{
FBSDKSharePhoto *photo = [[self alloc] init];
photo.photoAsset = photoAsset;
photo.userGenerated = userGenerated;
return photo;
}
#pragma mark - Properties
- (void)setImage:(UIImage *)image
{
_image = image;
_imageURL = nil;
_photoAsset = nil;
}
- (void)setImageURL:(NSURL *)imageURL
{
_image = nil;
_imageURL = [imageURL copy];
_photoAsset = nil;
}
- (void)setPhotoAsset:(PHAsset *)photoAsset
{
_image = nil;
_imageURL = nil;
_photoAsset = [photoAsset copy];
}
#pragma mark - Equality
- (NSUInteger)hash
{
NSUInteger subhashes[] = {
[_image hash],
[_imageURL hash],
[_photoAsset hash],
[_caption hash],
(_userGenerated ? 1u : 0u)
};
return [FBSDKMath hashWithIntegerArray:subhashes count:sizeof(subhashes) / sizeof(subhashes[0])];
}
- (BOOL)isEqual:(id)object
{
if (self == object) {
return YES;
}
if (![object isKindOfClass:[FBSDKSharePhoto class]]) {
return NO;
}
return [self isEqualToSharePhoto:(FBSDKSharePhoto *)object];
}
- (BOOL)isEqualToSharePhoto:(FBSDKSharePhoto *)photo
{
return (photo &&
(_userGenerated == photo.userGenerated) &&
[FBSDKInternalUtility object:_image isEqualToObject:photo.image] &&
[FBSDKInternalUtility object:_imageURL isEqualToObject:photo.imageURL] &&
[FBSDKInternalUtility object:_photoAsset isEqualToObject:photo.photoAsset] &&
[FBSDKInternalUtility object:_caption isEqualToObject:photo.caption]);
}
#pragma mark - FBSDKSharingValidation
- (BOOL)validateWithOptions:(FBSDKShareBridgeOptions)bridgeOptions error:(NSError *__autoreleasing *)errorRef
{
if (bridgeOptions & FBSDKShareBridgeOptionsPhotoImageURL) { // a web-based URL is required
if (_imageURL) {
if (_imageURL.isFileURL) {
if (errorRef != NULL) {
*errorRef = [FBSDKShareError invalidArgumentErrorWithName:@"imageURL"
value:_imageURL
message:@"Cannot refer to a local file resource."];
}
return NO;
} else {
return YES; // will bridge the image URL
}
} else {
if (errorRef != NULL) {
*errorRef = [FBSDKShareError invalidArgumentErrorWithName:@"photo"
value:self
message:@"imageURL is required."];
}
return NO;
}
} else if (_photoAsset) {
if (PHAssetMediaTypeImage == _photoAsset.mediaType) {
if (bridgeOptions & FBSDKShareBridgeOptionsPhotoAsset) {
return YES; // will bridge the PHAsset.localIdentifier
} else {
return YES; // will load the asset and bridge the image
}
} else {
if (errorRef != NULL) {
*errorRef = [FBSDKShareError invalidArgumentErrorWithName:@"photoAsset"
value:_photoAsset
message:@"Must refer to a photo or other static image."];
}
return NO;
}
} else if (_imageURL) {
if (_imageURL.isFileURL) {
return YES; // will load the contents of the file and bridge the image
} else {
if (errorRef != NULL) {
*errorRef = [FBSDKShareError invalidArgumentErrorWithName:@"imageURL"
value:_imageURL
message:@"Must refer to a local file resource."];
}
return NO;
}
} else if (_image) {
return YES; // will bridge the image
} else {
if (errorRef != NULL) {
*errorRef = [FBSDKShareError invalidArgumentErrorWithName:@"photo"
value:self
message:@"Must have an asset, image, or imageURL value."];
}
return NO;
}
}
#pragma mark - NSCoding
+ (BOOL)supportsSecureCoding
{
return YES;
}
- (id)initWithCoder:(NSCoder *)decoder
{
if ((self = [self init])) {
_image = [decoder decodeObjectOfClass:[UIImage class] forKey:kFBSDKSharePhotoImageKey];
_imageURL = [decoder decodeObjectOfClass:[NSURL class] forKey:kFBSDKSharePhotoImageURLKey];
NSString *localIdentifier = [decoder decodeObjectOfClass:[NSString class] forKey:kFBSDKSharePhotoAssetKey];
if (localIdentifier && (PHAuthorizationStatusAuthorized == [PHPhotoLibrary authorizationStatus])) {
_photoAsset = [PHAsset fetchAssetsWithLocalIdentifiers:@[localIdentifier] options:nil].firstObject;
}
_userGenerated = [decoder decodeBoolForKey:kFBSDKSharePhotoUserGeneratedKey];
_caption = [decoder decodeObjectOfClass:[NSString class] forKey:kFBSDKSharePhotoCaptionKey];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)encoder
{
[encoder encodeObject:_image forKey:kFBSDKSharePhotoImageKey];
[encoder encodeObject:_imageURL forKey:kFBSDKSharePhotoImageURLKey];
[encoder encodeObject:_photoAsset.localIdentifier forKey:kFBSDKSharePhotoAssetKey];
[encoder encodeBool:_userGenerated forKey:kFBSDKSharePhotoUserGeneratedKey];
[encoder encodeObject:_caption forKey:kFBSDKSharePhotoCaptionKey];
}
#pragma mark - NSCopying
- (id)copyWithZone:(NSZone *)zone
{
FBSDKSharePhoto *copy = [[FBSDKSharePhoto alloc] init];
copy->_image = [_image copy];
copy->_imageURL = [_imageURL copy];
copy->_photoAsset = [_photoAsset copy];
copy->_userGenerated = _userGenerated;
copy->_caption = [_caption copy];
return copy;
}
@end
@@ -1,41 +0,0 @@
// 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.
#import <Foundation/Foundation.h>
#import <FBSDKShareKit/FBSDKSharingContent.h>
/**
A model for photo content to be shared.
*/
@interface FBSDKSharePhotoContent : NSObject <FBSDKSharingContent>
/**
Photos to be shared.
@return Array of the photos (FBSDKSharePhoto)
*/
@property (nonatomic, copy) NSArray *photos;
/**
Compares the receiver to another photo content.
@param content The other content
@return YES if the receiver's values are equal to the other content's values; otherwise NO
*/
- (BOOL)isEqualToSharePhotoContent:(FBSDKSharePhotoContent *)content;
@end
@@ -1,229 +0,0 @@
// 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.
#import "FBSDKSharePhotoContent.h"
#import <Photos/Photos.h>
#import "FBSDKCoreKit+Internal.h"
#import "FBSDKHashtag.h"
#import "FBSDKShareError.h"
#import "FBSDKSharePhoto.h"
#import "FBSDKShareUtility.h"
#define FBSDK_SHARE_PHOTO_CONTENT_CONTENT_URL_KEY @"contentURL"
#define FBSDK_SHARE_PHOTO_CONTENT_HASHTAG_KEY @"hashtag"
#define FBSDK_SHARE_PHOTO_CONTENT_PEOPLE_IDS_KEY @"peopleIDs"
#define FBSDK_SHARE_PHOTO_CONTENT_PHOTOS_KEY @"photos"
#define FBSDK_SHARE_PHOTO_CONTENT_PLACE_ID_KEY @"placeID"
#define FBSDK_SHARE_PHOTO_CONTENT_REF_KEY @"ref"
#define FBSDK_SHARE_PHOTO_CONTENT_PAGE_ID_KEY @"pageID"
#define FBSDK_SHARE_PHOTO_CONTENT_UUID_KEY @"uuid"
@implementation FBSDKSharePhotoContent
#pragma mark - Properties
@synthesize contentURL = _contentURL;
@synthesize hashtag = _hashtag;
@synthesize peopleIDs = _peopleIDs;
@synthesize placeID = _placeID;
@synthesize ref = _ref;
@synthesize pageID = _pageID;
@synthesize shareUUID = _shareUUID;
#pragma mark - Initializer
- (instancetype)init
{
self = [super init];
if (self) {
_shareUUID = [NSUUID UUID].UUIDString;
}
return self;
}
#pragma mark - Setters
- (void)setPeopleIDs:(NSArray *)peopleIDs
{
[FBSDKShareUtility assertCollection:peopleIDs ofClass:[NSString class] name:@"peopleIDs"];
if (![FBSDKInternalUtility object:_peopleIDs isEqualToObject:peopleIDs]) {
_peopleIDs = [peopleIDs copy];
}
}
- (void)setPhotos:(NSArray *)photos
{
[FBSDKShareUtility assertCollection:photos ofClass:[FBSDKSharePhoto class] name:@"photos"];
if (![FBSDKInternalUtility object:_photos isEqualToObject:photos]) {
_photos = [photos copy];
}
}
#pragma mark - FBSDKSharingContent
- (void)addToParameters:(NSMutableDictionary<NSString *, id> *)parameters
bridgeOptions:(FBSDKShareBridgeOptions)bridgeOptions
{
NSMutableArray<UIImage *> *images = [[NSMutableArray alloc] init];
for (FBSDKSharePhoto *photo in _photos) {
if (photo.photoAsset) {
// load the asset and bridge the image
PHImageRequestOptions *imageRequestOptions = [[PHImageRequestOptions alloc] init];
imageRequestOptions.resizeMode = PHImageRequestOptionsResizeModeExact;
imageRequestOptions.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;
imageRequestOptions.synchronous = YES;
[[PHImageManager defaultManager]
requestImageForAsset:photo.photoAsset
targetSize:PHImageManagerMaximumSize
contentMode:PHImageContentModeDefault
options:imageRequestOptions
resultHandler:^(UIImage *image, NSDictionary<NSString *, id> *info) {
if (image) {
[images addObject:image];
}
}];
} else if (photo.imageURL) {
if (photo.imageURL.isFileURL) {
// load the contents of the file and bridge the image
UIImage *image = [UIImage imageWithContentsOfFile:[photo.imageURL absoluteString]];
if (image) {
[images addObject:photo.image];
}
}
} else if (photo.image) {
// bridge the image
[images addObject:photo.image];
}
}
if (images.count > 0) {
[FBSDKInternalUtility dictionary:parameters
setObject:images
forKey:@"photos"];
}
}
#pragma mark - FBSDKSharingValidation
- (BOOL)validateWithOptions:(FBSDKShareBridgeOptions)bridgeOptions error:(NSError *__autoreleasing *)errorRef
{
if (![FBSDKShareUtility validateArray:_photos minCount:1 maxCount:6 name:@"photos" error:errorRef]) {
return NO;
}
for (FBSDKSharePhoto *photo in _photos) {
if (![photo validateWithOptions:bridgeOptions error:errorRef]) {
return NO;
}
}
return YES;
}
#pragma mark - Equality
- (NSUInteger)hash
{
NSUInteger subhashes[] = {
[_contentURL hash],
[_hashtag hash],
[_peopleIDs hash],
[_photos hash],
[_placeID hash],
[_ref hash],
[_pageID hash],
[_shareUUID hash],
};
return [FBSDKMath hashWithIntegerArray:subhashes count:sizeof(subhashes) / sizeof(subhashes[0])];
}
- (BOOL)isEqual:(id)object
{
if (self == object) {
return YES;
}
if (![object isKindOfClass:[FBSDKSharePhotoContent class]]) {
return NO;
}
return [self isEqualToSharePhotoContent:(FBSDKSharePhotoContent *)object];
}
- (BOOL)isEqualToSharePhotoContent:(FBSDKSharePhotoContent *)content
{
return (content &&
[FBSDKInternalUtility object:_contentURL isEqualToObject:content.contentURL] &&
[FBSDKInternalUtility object:_hashtag isEqualToObject:content.hashtag] &&
[FBSDKInternalUtility object:_peopleIDs isEqualToObject:content.peopleIDs] &&
[FBSDKInternalUtility object:_photos isEqualToObject:content.photos] &&
[FBSDKInternalUtility object:_placeID isEqualToObject:content.placeID] &&
[FBSDKInternalUtility object:_ref isEqualToObject:content.ref] &&
[FBSDKInternalUtility object:_shareUUID isEqualToObject:content.shareUUID] &&
[FBSDKInternalUtility object:_pageID isEqualToObject:content.pageID]);
}
#pragma mark - NSCoding
+ (BOOL)supportsSecureCoding
{
return YES;
}
- (id)initWithCoder:(NSCoder *)decoder
{
if ((self = [self init])) {
_contentURL = [decoder decodeObjectOfClass:[NSURL class] forKey:FBSDK_SHARE_PHOTO_CONTENT_CONTENT_URL_KEY];
_hashtag = [decoder decodeObjectOfClass:[FBSDKHashtag class] forKey:FBSDK_SHARE_PHOTO_CONTENT_HASHTAG_KEY];
_peopleIDs = [decoder decodeObjectOfClass:[NSArray class] forKey:FBSDK_SHARE_PHOTO_CONTENT_PEOPLE_IDS_KEY];
NSSet *classes = [NSSet setWithObjects:[NSArray class], [FBSDKSharePhoto class], nil];
_photos = [decoder decodeObjectOfClasses:classes forKey:FBSDK_SHARE_PHOTO_CONTENT_PHOTOS_KEY];
_placeID = [decoder decodeObjectOfClass:[NSString class] forKey:FBSDK_SHARE_PHOTO_CONTENT_PLACE_ID_KEY];
_ref = [decoder decodeObjectOfClass:[NSString class] forKey:FBSDK_SHARE_PHOTO_CONTENT_REF_KEY];
_pageID = [decoder decodeObjectOfClass:[NSString class] forKey:FBSDK_SHARE_PHOTO_CONTENT_PAGE_ID_KEY];
_shareUUID = [decoder decodeObjectOfClass:[NSString class] forKey:FBSDK_SHARE_PHOTO_CONTENT_UUID_KEY];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)encoder
{
[encoder encodeObject:_contentURL forKey:FBSDK_SHARE_PHOTO_CONTENT_CONTENT_URL_KEY];
[encoder encodeObject:_hashtag forKey:FBSDK_SHARE_PHOTO_CONTENT_HASHTAG_KEY];
[encoder encodeObject:_peopleIDs forKey:FBSDK_SHARE_PHOTO_CONTENT_PEOPLE_IDS_KEY];
[encoder encodeObject:_photos forKey:FBSDK_SHARE_PHOTO_CONTENT_PHOTOS_KEY];
[encoder encodeObject:_placeID forKey:FBSDK_SHARE_PHOTO_CONTENT_PLACE_ID_KEY];
[encoder encodeObject:_ref forKey:FBSDK_SHARE_PHOTO_CONTENT_REF_KEY];
[encoder encodeObject:_pageID forKey:FBSDK_SHARE_PHOTO_CONTENT_PAGE_ID_KEY];
[encoder encodeObject:_shareUUID forKey:FBSDK_SHARE_PHOTO_CONTENT_UUID_KEY];
}
#pragma mark - NSCopying
- (id)copyWithZone:(NSZone *)zone
{
FBSDKSharePhotoContent *copy = [[FBSDKSharePhotoContent alloc] init];
copy->_contentURL = [_contentURL copy];
copy->_hashtag = [_hashtag copy];
copy->_peopleIDs = [_peopleIDs copy];
copy->_photos = [_photos copy];
copy->_placeID = [_placeID copy];
copy->_ref = [_ref copy];
copy->_pageID = [_pageID copy];
copy->_shareUUID = [_shareUUID copy];
return copy;
}
@end
@@ -1,102 +0,0 @@
// 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.
#import <UIKit/UIKit.h>
#import <FBSDKCoreKit/FBSDKCopying.h>
#import <FBSDKShareKit/FBSDKSharingValidation.h>
@class FBSDKSharePhoto;
@class PHAsset;
/**
A video for sharing.
*/
@interface FBSDKShareVideo : NSObject <FBSDKCopying, FBSDKSharingValidation, NSSecureCoding>
/**
Convenience method to build a new video object from raw data.
- Parameter data: The NSData object that holds the raw video data.
*/
+ (instancetype)videoWithData:(NSData *)data;
/**
Convenience method to build a new video object with NSData and a previewPhoto.
- Parameter data: The NSData object that holds the raw video data.
- Parameter previewPhoto: The photo that represents the video.
*/
+ (instancetype)videoWithData:(NSData *)data previewPhoto:(FBSDKSharePhoto *)previewPhoto;
/**
Convenience method to build a new video object with a PHAsset.
@param videoAsset The PHAsset that represents the video in the Photos library.
*/
+ (instancetype)videoWithVideoAsset:(PHAsset *)videoAsset;
/**
Convenience method to build a new video object with a PHAsset and a previewPhoto.
@param videoAsset The PHAsset that represents the video in the Photos library.
@param previewPhoto The photo that represents the video.
*/
+ (instancetype)videoWithVideoAsset:(PHAsset *)videoAsset previewPhoto:(FBSDKSharePhoto *)previewPhoto;
/**
Convenience method to build a new video object with a videoURL.
@param videoURL The URL to the video.
*/
+ (instancetype)videoWithVideoURL:(NSURL *)videoURL;
/**
Convenience method to build a new video object with a videoURL and a previewPhoto.
@param videoURL The URL to the video.
@param previewPhoto The photo that represents the video.
*/
+ (instancetype)videoWithVideoURL:(NSURL *)videoURL previewPhoto:(FBSDKSharePhoto *)previewPhoto;
/**
The raw video data.
- Returns: The video data.
*/
@property (nonatomic, strong) NSData *data;
/**
The representation of the video in the Photos library.
@return PHAsset that represents the video in the Photos library.
*/
@property (nonatomic, copy) PHAsset *videoAsset;
/**
The file URL to the video.
@return URL that points to the location of the video on disk
*/
@property (nonatomic, copy) NSURL *videoURL;
/**
The photo that represents the video.
@return The photo
*/
@property (nonatomic, copy) FBSDKSharePhoto *previewPhoto;
/**
Compares the receiver to another video.
@param video The other video
@return YES if the receiver's values are equal to the other video's values; otherwise NO
*/
- (BOOL)isEqualToShareVideo:(FBSDKShareVideo *)video;
@end
@@ -1,265 +0,0 @@
// 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.
#import "FBSDKShareVideo.h"
#import <Photos/Photos.h>
#import "FBSDKCoreKit+Internal.h"
#import "FBSDKShareError.h"
#import "FBSDKSharePhoto.h"
#import "FBSDKShareUtility.h"
NSString *const kFBSDKShareVideoAssetKey = @"videoAsset";
NSString *const kFBSDKShareVideoDataKey = @"data";
NSString *const kFBSDKShareVideoPreviewPhotoKey = @"previewPhoto";
NSString *const kFBSDKShareVideoURLKey = @"videoURL";
@implementation FBSDKShareVideo
#pragma mark - Class Methods
+ (instancetype)videoWithData:(NSData *)data
{
FBSDKShareVideo *video = [[FBSDKShareVideo alloc] init];
video.data = data;
return video;
}
+ (instancetype)videoWithData:(NSData *)data previewPhoto:(FBSDKSharePhoto *)previewPhoto
{
FBSDKShareVideo *video = [[FBSDKShareVideo alloc] init];
video.data = data;
video.previewPhoto = previewPhoto;
return video;
}
+ (instancetype)videoWithVideoAsset:(PHAsset *)videoAsset
{
FBSDKShareVideo *video = [[FBSDKShareVideo alloc] init];
video.videoAsset = videoAsset;
return video;
}
+ (instancetype)videoWithVideoAsset:(PHAsset *)videoAsset previewPhoto:(FBSDKSharePhoto *)previewPhoto
{
FBSDKShareVideo *video = [[FBSDKShareVideo alloc] init];
video.videoAsset = videoAsset;
video.previewPhoto = previewPhoto;
return video;
}
+ (instancetype)videoWithVideoURL:(NSURL *)videoURL
{
FBSDKShareVideo *video = [[FBSDKShareVideo alloc] init];
video.videoURL = videoURL;
return video;
}
+ (instancetype)videoWithVideoURL:(NSURL *)videoURL previewPhoto:(FBSDKSharePhoto *)previewPhoto
{
FBSDKShareVideo *video = [[FBSDKShareVideo alloc] init];
video.videoURL = videoURL;
video.previewPhoto = previewPhoto;
return video;
}
#pragma mark - Properties
- (void)setData:(NSData *)data
{
_data = data;
_videoAsset = nil;
_videoURL = nil;
_previewPhoto = nil;
}
- (void)setVideoAsset:(PHAsset *)videoAsset
{
_data = nil;
_videoAsset = [videoAsset copy];
_videoURL = nil;
_previewPhoto = nil;
}
- (void)setVideoURL:(NSURL *)videoURL
{
_data = nil;
_videoAsset = nil;
_videoURL = [videoURL copy];
_previewPhoto = nil;
}
#pragma mark - Equality
- (NSUInteger)hash
{
NSUInteger subhashes[] = {
[_data hash],
[_videoAsset hash],
[_videoURL hash],
[_previewPhoto hash],
};
return [FBSDKMath hashWithIntegerArray:subhashes count:sizeof(subhashes) / sizeof(subhashes[0])];
}
- (BOOL)isEqual:(id)object
{
if (self == object) {
return YES;
}
if (![object isKindOfClass:[FBSDKShareVideo class]]) {
return NO;
}
return [self isEqualToShareVideo:(FBSDKShareVideo *)object];
}
- (BOOL)isEqualToShareVideo:(FBSDKShareVideo *)video
{
return (video &&
[FBSDKInternalUtility object:_data isEqualToObject:video.data] &&
[FBSDKInternalUtility object:_videoAsset isEqualToObject:video.videoAsset] &&
[FBSDKInternalUtility object:_videoURL isEqualToObject:video.videoURL] &&
[FBSDKInternalUtility object:_previewPhoto isEqualToObject:video.previewPhoto]);
}
#pragma mark - FBSDKSharingValidation
- (BOOL)_validateData:(NSData *)data
withOptions:(FBSDKShareBridgeOptions)bridgeOptions
error:(NSError *__autoreleasing *)errorRef
{
if (data) {
if (bridgeOptions & FBSDKShareBridgeOptionsVideoData) {
return YES; // will bridge the data
}
}
if ((errorRef != NULL) && !*errorRef) {
*errorRef = [FBSDKShareError invalidArgumentErrorWithName:@"data"
value:data
message:@"Cannot share video data."];
}
return NO;
}
- (BOOL)_validateVideoAsset:(PHAsset *)videoAsset
withOptions:(FBSDKShareBridgeOptions)bridgeOptions
error:(NSError *__autoreleasing *)errorRef
{
if (videoAsset) {
if (PHAssetMediaTypeVideo == videoAsset.mediaType) {
if (bridgeOptions & FBSDKShareBridgeOptionsVideoAsset) {
return YES; // will bridge the PHAsset.localIdentifier
} else {
return YES; // will bridge the legacy "assets-library" URL from AVAsset
}
} else {
if (errorRef != NULL) {
*errorRef = [FBSDKShareError invalidArgumentErrorWithName:@"videoAsset"
value:videoAsset
message:@"Must refer to a video file."];
}
return NO;
}
}
return NO;
}
- (BOOL)_validateVideoURL:(NSURL *)videoURL
withOptions:(FBSDKShareBridgeOptions)bridgeOptions
error:(NSError *__autoreleasing *)errorRef
{
if (videoURL) {
if ([[videoURL.scheme lowercaseString] isEqualToString:@"assets-library"]) {
return YES; // will bridge the legacy "assets-library" URL
} else if (videoURL.isFileURL) {
if (bridgeOptions & FBSDKShareBridgeOptionsVideoData) {
return YES; // will load the contents of the file and bridge the data
}
}
}
if ((errorRef != NULL) && !*errorRef) {
*errorRef = [FBSDKShareError invalidArgumentErrorWithName:@"videoURL"
value:videoURL
message:@"Must refer to an asset file."];
}
return NO;
}
- (BOOL)validateWithOptions:(FBSDKShareBridgeOptions)bridgeOptions error:(NSError *__autoreleasing *)errorRef
{
// validate that a valid asset, data, or videoURL value has been set.
// don't validate the preview photo; if it isn't valid it'll be dropped from the share; a default one may be created if needed.
if (_videoAsset) {
return [self _validateVideoAsset:_videoAsset withOptions:bridgeOptions error:errorRef];
} else if (_data) {
return [self _validateData:_data withOptions:bridgeOptions error:errorRef];
} else if (_videoURL) {
return [self _validateVideoURL:_videoURL withOptions:bridgeOptions error:errorRef];
} else {
if ((errorRef != NULL) && !*errorRef) {
*errorRef = [FBSDKShareError invalidArgumentErrorWithName:@"video"
value:self
message:@"Must have an asset, data, or videoURL value."];
}
return NO;
}
}
#pragma mark - NSCoding
+ (BOOL)supportsSecureCoding
{
return YES;
}
- (id)initWithCoder:(NSCoder *)decoder
{
if ((self = [self init])) {
_data = [decoder decodeObjectOfClass:[NSData class] forKey:kFBSDKShareVideoDataKey];
NSString *localIdentifier = [decoder decodeObjectOfClass:[NSString class] forKey:kFBSDKShareVideoAssetKey];
if (localIdentifier && (PHAuthorizationStatusAuthorized == [PHPhotoLibrary authorizationStatus])) {
_videoAsset = [PHAsset fetchAssetsWithLocalIdentifiers:@[localIdentifier] options:nil].firstObject;
}
_videoURL = [decoder decodeObjectOfClass:[NSURL class] forKey:kFBSDKShareVideoURLKey];
_previewPhoto = [decoder decodeObjectOfClass:[FBSDKSharePhoto class] forKey:kFBSDKShareVideoPreviewPhotoKey];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)encoder
{
[encoder encodeObject:_data forKey:kFBSDKShareVideoDataKey];
[encoder encodeObject:_videoAsset.localIdentifier forKey:kFBSDKShareVideoAssetKey];
[encoder encodeObject:_videoURL forKey:kFBSDKShareVideoURLKey];
[encoder encodeObject:_previewPhoto forKey:kFBSDKShareVideoPreviewPhotoKey];
}
#pragma mark - NSCopying
- (id)copyWithZone:(NSZone *)zone
{
FBSDKShareVideo *copy = [[FBSDKShareVideo alloc] init];
copy->_data = [_data copy];
copy->_videoAsset = [_videoAsset copy];
copy->_videoURL = [_videoURL copy];
copy->_previewPhoto = [_previewPhoto copy];
return copy;
}
@end
@@ -1,50 +0,0 @@
// 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.
#import <Foundation/Foundation.h>
#import <FBSDKShareKit/FBSDKSharePhoto.h>
#import <FBSDKShareKit/FBSDKShareVideo.h>
#import <FBSDKShareKit/FBSDKSharingContent.h>
/**
A model for video content to be shared.
*/
@interface FBSDKShareVideoContent : NSObject <FBSDKSharingContent>
/**
The photo that represents the video.
@return The photo
*/
@property (nonatomic, copy) FBSDKSharePhoto *previewPhoto
DEPRECATED_MSG_ATTRIBUTE("Use `video.previewPhoto`");
/**
The video to be shared.
@return The video
*/
@property (nonatomic, copy) FBSDKShareVideo *video;
/**
Compares the receiver to another video content.
@param content The other content
@return YES if the receiver's values are equal to the other content's values; otherwise NO
*/
- (BOOL)isEqualToShareVideoContent:(FBSDKShareVideoContent *)content;
@end
@@ -1,249 +0,0 @@
// 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.
#import "FBSDKShareVideoContent.h"
#import <Photos/Photos.h>
#import "FBSDKCoreKit+Internal.h"
#import "FBSDKHashtag.h"
#import "FBSDKShareUtility.h"
#define FBSDK_SHARE_VIDEO_CONTENT_CONTENT_URL_KEY @"contentURL"
#define FBSDK_SHARE_VIDEO_CONTENT_HASHTAG_KEY @"hashtag"
#define FBSDK_SHARE_VIDEO_CONTENT_PEOPLE_IDS_KEY @"peopleIDs"
#define FBSDK_SHARE_VIDEO_CONTENT_PLACE_ID_KEY @"placeID"
#define FBSDK_SHARE_VIDEO_CONTENT_PREVIEW_PHOTO_KEY @"previewPhoto"
#define FBSDK_SHARE_VIDEO_CONTENT_REF_KEY @"ref"
#define FBSDK_SHARE_VIDEO_CONTENT_PAGE_ID_KEY @"pageID"
#define FBSDK_SHARE_VIDEO_CONTENT_VIDEO_KEY @"video"
#define FBSDK_SHARE_VIDEO_CONTENT_UUID_KEY @"uuid"
@implementation FBSDKShareVideoContent
#pragma mark - Properties
@synthesize contentURL = _contentURL;
@synthesize hashtag = _hashtag;
@synthesize peopleIDs = _peopleIDs;
@synthesize placeID = _placeID;
@synthesize ref = _ref;
@synthesize pageID = _pageID;
@synthesize shareUUID = _shareUUID;
#pragma mark - Initializer
- (instancetype)init
{
self = [super init];
if (self) {
_shareUUID = [NSUUID UUID].UUIDString;
}
return self;
}
#pragma mark - Setters
- (void)setPeopleIDs:(NSArray *)peopleIDs
{
[FBSDKShareUtility assertCollection:peopleIDs ofClass:[NSString class] name:@"peopleIDs"];
if (![FBSDKInternalUtility object:_peopleIDs isEqualToObject:peopleIDs]) {
_peopleIDs = [peopleIDs copy];
}
}
#pragma mark - FBSDKSharingContent
- (void)addToParameters:(NSMutableDictionary<NSString *, id> *)parameters
bridgeOptions:(FBSDKShareBridgeOptions)bridgeOptions
{
NSMutableDictionary<NSString *, id> *videoParameters = [[NSMutableDictionary alloc] init];
if (_video.videoAsset) {
if (bridgeOptions & FBSDKShareBridgeOptionsVideoAsset) {
// bridge the PHAsset.localIdentifier
[FBSDKInternalUtility dictionary:videoParameters
setObject:_video.videoAsset.localIdentifier
forKey:@"assetIdentifier"];
} else {
// bridge the legacy "assets-library" URL from AVAsset
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
PHVideoRequestOptions *options = [[PHVideoRequestOptions alloc] init];
options.version = PHVideoRequestOptionsVersionCurrent;
options.deliveryMode = PHVideoRequestOptionsDeliveryModeAutomatic;
options.networkAccessAllowed = YES;
[[PHImageManager defaultManager] requestAVAssetForVideo:_video.videoAsset
options:options
resultHandler:^(AVAsset *avAsset, AVAudioMix *audioMix, NSDictionary<NSString *, id> *info) {
NSURL *filePathURL = [[(AVURLAsset *)avAsset URL] filePathURL];
NSString *pathExtension = [filePathURL pathExtension];
NSString *localIdentifier = [self->_video.videoAsset localIdentifier];
NSRange range = [localIdentifier rangeOfString:@"/"];
NSString *uuid = [localIdentifier substringToIndex:range.location];
NSString *assetPath = [NSString stringWithFormat:@"assets-library://asset/asset.%@?id=%@&ext=%@", pathExtension, uuid, pathExtension];
if (assetPath) {
[FBSDKInternalUtility dictionary:videoParameters
setObject:[NSURL URLWithString:assetPath]
forKey:@"assetURL"];
}
dispatch_semaphore_signal(semaphore);
}];
dispatch_semaphore_wait(semaphore, dispatch_time(DISPATCH_TIME_NOW, 500 * NSEC_PER_MSEC));
}
} else if (_video.data) {
if (bridgeOptions & FBSDKShareBridgeOptionsVideoData) {
// bridge the data
[FBSDKInternalUtility dictionary:videoParameters
setObject:_video.data
forKey:@"data"];
}
} else if (_video.videoURL) {
if ([[_video.videoURL.scheme lowercaseString] isEqualToString:@"assets-library"]) {
// bridge the legacy "assets-library" URL
[FBSDKInternalUtility dictionary:videoParameters
setObject:_video.videoURL
forKey:@"assetURL"];
} else if (_video.videoURL.isFileURL) {
if (bridgeOptions & FBSDKShareBridgeOptionsVideoData) {
// load the contents of the file and bridge the data
NSData *data = [NSData dataWithContentsOfURL:_video.videoURL options:NSDataReadingMappedIfSafe error:NULL];
[FBSDKInternalUtility dictionary:videoParameters
setObject:data
forKey:@"data"];
}
}
}
[FBSDKInternalUtility dictionary:videoParameters
setObject:[FBSDKShareUtility convertPhoto:_previewPhoto]
forKey:@"previewPhoto"];
[FBSDKInternalUtility dictionary:parameters
setObject:videoParameters
forKey:@"video"];
}
#pragma mark - FBSDKSharingValidation
- (BOOL)validateWithOptions:(FBSDKShareBridgeOptions)bridgeOptions error:(NSError *__autoreleasing *)errorRef
{
if (![FBSDKShareUtility validateRequiredValue:_video name:@"video" error:errorRef]) {
return NO;
}
return [_video validateWithOptions:bridgeOptions error:errorRef];
}
#pragma mark - Equality
- (NSUInteger)hash
{
NSUInteger subhashes[] = {
[_contentURL hash],
[_hashtag hash],
[_peopleIDs hash],
[_placeID hash],
[_previewPhoto hash],
[_ref hash],
[_pageID hash],
[_video hash],
[_shareUUID hash],
};
return [FBSDKMath hashWithIntegerArray:subhashes count:sizeof(subhashes) / sizeof(subhashes[0])];
}
- (BOOL)isEqual:(id)object
{
if (self == object) {
return YES;
}
if (![object isKindOfClass:[FBSDKShareVideoContent class]]) {
return NO;
}
return [self isEqualToShareVideoContent:(FBSDKShareVideoContent *)object];
}
- (BOOL)isEqualToShareVideoContent:(FBSDKShareVideoContent *)content
{
return (content &&
[FBSDKInternalUtility object:_contentURL isEqualToObject:content.contentURL] &&
[FBSDKInternalUtility object:_hashtag isEqualToObject:content.hashtag] &&
[FBSDKInternalUtility object:_peopleIDs isEqualToObject:content.peopleIDs] &&
[FBSDKInternalUtility object:_placeID isEqualToObject:content.placeID] &&
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[FBSDKInternalUtility object:_previewPhoto isEqualToObject:content.previewPhoto] &&
#pragma clang diagnostic pop
[FBSDKInternalUtility object:_ref isEqualToObject:content.ref] &&
[FBSDKInternalUtility object:_pageID isEqualToObject:content.pageID] &&
[FBSDKInternalUtility object:_shareUUID isEqualToObject:content.shareUUID] &&
[FBSDKInternalUtility object:_video isEqualToObject:content.video]);
}
#pragma mark - NSCoding
+ (BOOL)supportsSecureCoding
{
return YES;
}
- (id)initWithCoder:(NSCoder *)decoder
{
if ((self = [self init])) {
_contentURL = [decoder decodeObjectOfClass:[NSURL class] forKey:FBSDK_SHARE_VIDEO_CONTENT_CONTENT_URL_KEY];
_hashtag = [decoder decodeObjectOfClass:[FBSDKHashtag class] forKey:FBSDK_SHARE_VIDEO_CONTENT_HASHTAG_KEY];
_peopleIDs = [decoder decodeObjectOfClass:[NSArray class] forKey:FBSDK_SHARE_VIDEO_CONTENT_PEOPLE_IDS_KEY];
_placeID = [decoder decodeObjectOfClass:[NSString class] forKey:FBSDK_SHARE_VIDEO_CONTENT_PLACE_ID_KEY];
_previewPhoto = [decoder decodeObjectOfClass:[FBSDKSharePhoto class]
forKey:FBSDK_SHARE_VIDEO_CONTENT_PREVIEW_PHOTO_KEY];
_ref = [decoder decodeObjectOfClass:[NSString class] forKey:FBSDK_SHARE_VIDEO_CONTENT_REF_KEY];
_pageID = [decoder decodeObjectOfClass:[NSString class] forKey:FBSDK_SHARE_VIDEO_CONTENT_PAGE_ID_KEY];
_video = [decoder decodeObjectOfClass:[FBSDKShareVideo class] forKey:FBSDK_SHARE_VIDEO_CONTENT_VIDEO_KEY];
_shareUUID = [decoder decodeObjectOfClass:[NSString class] forKey:FBSDK_SHARE_VIDEO_CONTENT_UUID_KEY];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)encoder
{
[encoder encodeObject:_contentURL forKey:FBSDK_SHARE_VIDEO_CONTENT_CONTENT_URL_KEY];
[encoder encodeObject:_hashtag forKey:FBSDK_SHARE_VIDEO_CONTENT_HASHTAG_KEY];
[encoder encodeObject:_peopleIDs forKey:FBSDK_SHARE_VIDEO_CONTENT_PEOPLE_IDS_KEY];
[encoder encodeObject:_placeID forKey:FBSDK_SHARE_VIDEO_CONTENT_PLACE_ID_KEY];
[encoder encodeObject:_previewPhoto forKey:FBSDK_SHARE_VIDEO_CONTENT_PREVIEW_PHOTO_KEY];
[encoder encodeObject:_ref forKey:FBSDK_SHARE_VIDEO_CONTENT_REF_KEY];
[encoder encodeObject:_pageID forKey:FBSDK_SHARE_VIDEO_CONTENT_PAGE_ID_KEY];
[encoder encodeObject:_video forKey:FBSDK_SHARE_VIDEO_CONTENT_VIDEO_KEY];
[encoder encodeObject:_shareUUID forKey:FBSDK_SHARE_VIDEO_CONTENT_UUID_KEY];
}
#pragma mark - NSCopying
- (id)copyWithZone:(NSZone *)zone
{
FBSDKShareVideoContent *copy = [[FBSDKShareVideoContent alloc] init];
copy->_contentURL = [_contentURL copy];
copy->_hashtag = [_hashtag copy];
copy->_peopleIDs = [_peopleIDs copy];
copy->_placeID = [_placeID copy];
copy->_previewPhoto = [_previewPhoto copy];
copy->_ref = [_ref copy];
copy->_pageID = [_pageID copy];
copy->_video = [_video copy];
copy->_shareUUID = [_shareUUID copy];
return copy;
}
@end
@@ -1,117 +0,0 @@
// 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.
#import <Foundation/Foundation.h>
#import <FBSDKShareKit/FBSDKSharingContent.h>
@protocol FBSDKSharingDelegate;
/**
The common interface for components that initiate sharing.
@see FBSDKShareDialog
@see FBSDKMessageDialog
@see FBSDKShareAPI
*/
@protocol FBSDKSharing <NSObject>
/**
The receiver's delegate or nil if it doesn't have a delegate.
*/
@property (nonatomic, weak) id<FBSDKSharingDelegate> delegate;
/**
The content to be shared.
*/
@property (nonatomic, copy) id<FBSDKSharingContent> shareContent;
/**
A Boolean value that indicates whether the receiver should fail if it finds an error with the share content.
If NO, the sharer will still be displayed without the data that was mis-configured. For example, an
invalid placeID specified on the shareContent would produce a data error.
*/
@property (nonatomic, assign) BOOL shouldFailOnDataError;
/**
Validates the content on the receiver.
@param errorRef If an error occurs, upon return contains an NSError object that describes the problem.
@return YES if the content is valid, otherwise NO.
*/
- (BOOL)validateWithError:(NSError **)errorRef;
@end
/**
The common interface for dialogs that initiate sharing.
*/
@protocol FBSDKSharingDialog <FBSDKSharing>
/**
A Boolean value that indicates whether the receiver can initiate a share.
May return NO if the appropriate Facebook app is not installed and is required or an access token is
required but not available. This method does not validate the content on the receiver, so this can be checked before
building up the content.
@see [FBSDKSharing validateWithError:]
@return YES if the receiver can share, otherwise NO.
*/
- (BOOL)canShow;
/**
Shows the dialog.
@return YES if the receiver was able to begin sharing, otherwise NO.
*/
- (BOOL)show;
@end
/**
A delegate for FBSDKSharing.
The delegate is notified with the results of the sharer as long as the application has permissions to
receive the information. For example, if the person is not signed into the containing app, the sharer may not be able
to distinguish between completion of a share and cancellation.
*/
@protocol FBSDKSharingDelegate <NSObject>
/**
Sent to the delegate when the share completes without error or cancellation.
@param sharer The FBSDKSharing that completed.
@param results The results from the sharer. This may be nil or empty.
*/
- (void)sharer:(id<FBSDKSharing>)sharer didCompleteWithResults:(NSDictionary *)results;
/**
Sent to the delegate when the sharer encounters an error.
@param sharer The FBSDKSharing that completed.
@param error The error.
*/
- (void)sharer:(id<FBSDKSharing>)sharer didFailWithError:(NSError *)error;
/**
Sent to the delegate when the sharer is cancelled.
@param sharer The FBSDKSharing that completed.
*/
- (void)sharerDidCancel:(id<FBSDKSharing>)sharer;
@end
@@ -1,37 +0,0 @@
// 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.
#import <Foundation/Foundation.h>
#import <FBSDKShareKit/FBSDKSharingContent.h>
/**
The common interface for sharing buttons.
@see FBSDKSendButton
@see FBSDKShareButton
*/
@protocol FBSDKSharingButton <NSObject>
/**
The content to be shared.
*/
@property (nonatomic, copy) id<FBSDKSharingContent> shareContent;
@end
@@ -1,85 +0,0 @@
// 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.
#import <Foundation/Foundation.h>
#import <FBSDKCoreKit/FBSDKCopying.h>
#import <FBSDKShareKit/FBSDKSharingValidation.h>
@class FBSDKHashtag;
/**
A base interface for content to be shared.
*/
@protocol FBSDKSharingContent <FBSDKCopying, FBSDKSharingValidation, NSSecureCoding>
/**
URL for the content being shared.
This URL will be checked for all link meta tags for linking in platform specific ways. See documentation
for App Links (https://developers.facebook.com/docs/applinks/)
@return URL representation of the content link
*/
@property (nonatomic, copy) NSURL *contentURL;
/**
Hashtag for the content being shared.
@return The hashtag for the content being shared.
*/
@property (nonatomic, copy) FBSDKHashtag *hashtag;
/**
List of IDs for taggable people to tag with this content.
See documentation for Taggable Friends
(https://developers.facebook.com/docs/graph-api/reference/user/taggable_friends)
@return Array of IDs for people to tag (NSString)
*/
@property (nonatomic, copy) NSArray *peopleIDs;
/**
The ID for a place to tag with this content.
@return The ID for the place to tag
*/
@property (nonatomic, copy) NSString *placeID;
/**
A value to be added to the referrer URL when a person follows a link from this shared content on feed.
@return The ref for the content.
*/
@property (nonatomic, copy) NSString *ref;
/**
For shares into Messenger, this pageID will be used to map the app to page and attach attribution to the share.
@return The ID of the Facebok page this share is associated with.
*/
@property (nonatomic, copy) NSString *pageID;
/**
A unique identifier for a share involving this content, useful for tracking purposes.
@return A unique string identifying this share data.
*/
@property (nonatomic, copy, readonly) NSString *shareUUID;
/**
Adds content to a dictionary as key/value pairs.
- Parameter parameters: A mutable dictionary that may be appended with key/value pairs of content.
*/
- (void)addToParameters:(NSMutableDictionary<NSString *, id> *)parameters
bridgeOptions:(FBSDKShareBridgeOptions)bridgeOptions;
@end
@@ -1,33 +0,0 @@
// 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.
#import "FBSDKShareDialogMode.h"
/**
A base interface for indicating a custom URL scheme
*/
@protocol FBSDKSharingScheme
/**
Asks the receiver to provide a custom scheme.
- Parameter mode: The intended dialog mode for sharing the content.
- Returns: A custom URL scheme to use for the specified mode, or nil.
*/
- (nullable NSString *)schemeForMode:(FBSDKShareDialogMode)mode;
@end
@@ -1,46 +0,0 @@
// 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.
#import <Foundation/Foundation.h>
/**
Flags to indicate support for newer bridge options beyond the initial 20130410 implementation.
*/
typedef NS_OPTIONS(NSUInteger, FBSDKShareBridgeOptions)
{
FBSDKShareBridgeOptionsDefault = 0,
FBSDKShareBridgeOptionsPhotoAsset = 1 << 0,
FBSDKShareBridgeOptionsPhotoImageURL = 1 << 1, // if set, a web-based URL is required; asset, image, and imageURL.isFileURL not allowed
FBSDKShareBridgeOptionsVideoAsset = 1 << 2,
FBSDKShareBridgeOptionsVideoData = 1 << 3,
FBSDKShareBridgeOptionsWebHashtag = 1 << 4, // if set, pass the hashtag as a string value, not an array of one string
};
/**
A base interface for validation of content and media.
*/
@protocol FBSDKSharingValidation
/**
Asks the receiver to validate that its content or media values are valid.
- Parameter errorRef: Optional, will receive an FBSDKShareError if the values are not valid.
- Returns: YES if the receiver's values are valid; otherwise NO
*/
- (BOOL)validateWithOptions:(FBSDKShareBridgeOptions)bridgeOptions error:(NSError *__autoreleasing *)errorRef;
@end
@@ -1,25 +0,0 @@
// 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.
#import <FBSDKShareKit/FBSDKCameraEffectArguments.h>
@interface FBSDKCameraEffectArguments ()
- (NSDictionary *)allArguments;
@end
@@ -1,25 +0,0 @@
// 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.
#import <FBSDKShareKit/FBSDKCameraEffectTextures.h>
@interface FBSDKCameraEffectTextures ()
- (NSDictionary<NSString *, UIImage *> *)allTextures;
@end
@@ -1,25 +0,0 @@
// 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.
#import <UIKit/UIKit.h>
#import "FBSDKCoreKit+Internal.h"
@interface FBSDKCheckmarkIcon : FBSDKIcon
@end
@@ -1,43 +0,0 @@
// 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.
#import "FBSDKCheckmarkIcon.h"
@implementation FBSDKCheckmarkIcon
- (CGPathRef)pathWithSize:(CGSize)size
{
CGAffineTransform transformValue = CGAffineTransformMakeScale(size.width / 100.0, size.height / 100.0);
CGAffineTransform *transform = &transformValue;
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, transform, 0.0, 50.0);
const CGPoint points[] = {
CGPointMake(12.0, 38.0),
CGPointMake(37.0, 63.0),
CGPointMake(87.0, 13.0),
CGPointMake(99.0, 25.0),
CGPointMake(37.0, 87.0),
CGPointMake(0.0, 48.0),
};
CGPathAddLines(path, transform, points, sizeof(points) / sizeof(points[0]));
CGPathRef result = CGPathCreateCopy(path);
CGPathRelease(path);
return CFAutorelease(result);
}
@end
@@ -1,26 +0,0 @@
// 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.
#import <Foundation/Foundation.h>
@interface FBSDKGameRequestFrictionlessRecipientCache : NSObject
- (BOOL)recipientsAreFrictionless:(id)recipients;
- (void)updateWithResults:(NSDictionary *)results;
@end
@@ -1,101 +0,0 @@
// 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.
#import "FBSDKGameRequestFrictionlessRecipientCache.h"
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import "FBSDKCoreKit+Internal.h"
@implementation FBSDKGameRequestFrictionlessRecipientCache
{
NSSet *_recipientIDs;
}
#pragma mark - Object Lifecycle
- (instancetype)init
{
if ((self = [super init])) {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(_accessTokenDidChangeNotification:)
name:FBSDKAccessTokenDidChangeNotification
object:nil];
[self _updateCache];
}
return self;
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
#pragma mark - Public API
- (BOOL)recipientsAreFrictionless:(id)recipients
{
if (!recipients) {
return NO;
}
NSArray *recipientIDArray = [FBSDKTypeUtility arrayValue:recipients];
if (!recipientIDArray && [recipients isKindOfClass:[NSString class]]) {
recipientIDArray = [recipients componentsSeparatedByString:@","];
}
NSSet *recipientIDs = [[NSSet alloc] initWithArray:recipientIDArray];
return [recipientIDs isSubsetOfSet:_recipientIDs];
}
- (void)updateWithResults:(NSDictionary *)results
{
if ([FBSDKTypeUtility boolValue:results[@"updated_frictionless"]]) {
[self _updateCache];
}
}
#pragma mark - Helper Methods
- (void)_accessTokenDidChangeNotification:(NSNotification *)notification
{
if (![notification.userInfo[FBSDKAccessTokenDidChangeUserID] boolValue]) {
return;
}
_recipientIDs = nil;
[self _updateCache];
}
- (void)_updateCache
{
if (![FBSDKAccessToken currentAccessToken]) {
_recipientIDs = nil;
return;
}
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc] initWithGraphPath:@"me/apprequestformerrecipients"
parameters:@{@"fields":@""}
flags:(FBSDKGraphRequestFlagDoNotInvalidateTokenOnError |
FBSDKGraphRequestFlagDisableErrorRecovery)];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (!error) {
NSArray *items = [FBSDKTypeUtility arrayValue:result[@"data"]];
NSArray *recipientIDs = [items valueForKey:@"recipient_id"];
self->_recipientIDs = [[NSSet alloc] initWithArray:recipientIDs];
}
}];
}
@end
@@ -1,48 +0,0 @@
// 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.
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <FBSDKCoreKit/FBSDKMacros.h>
#import <FBSDKShareKit/FBSDKLikeObjectType.h>
FBSDK_EXTERN NSString *const FBSDKLikeActionControllerDidDisableNotification;
FBSDK_EXTERN NSString *const FBSDKLikeActionControllerDidResetNotification;
FBSDK_EXTERN NSString *const FBSDKLikeActionControllerDidUpdateNotification;
FBSDK_EXTERN NSString *const FBSDKLikeActionControllerAnimatedKey;
@interface FBSDKLikeActionController : NSObject <NSDiscardableContent, NSSecureCoding>
+ (BOOL)isDisabled;
// this method will call beginContentAccess before returning the instance
+ (instancetype)likeActionControllerForObjectID:(NSString *)objectID objectType:(FBSDKLikeObjectType)objectType;
@property (nonatomic, copy, readonly) NSDate *lastUpdateTime;
@property (nonatomic, copy, readonly) NSString *likeCountString;
@property (nonatomic, copy, readonly) NSString *objectID;
@property (nonatomic, assign, readonly) FBSDKLikeObjectType objectType;
@property (nonatomic, assign, readonly) BOOL objectIsLiked;
@property (nonatomic, copy, readonly) NSString *socialSentence;
- (void)refresh;
- (void)toggleLikeWithSoundEnabled:(BOOL)soundEnabled analyticsParameters:(NSDictionary *)analyticsParameters fromViewController:(UIViewController *)fromViewController;
@end
File diff suppressed because it is too large. Load diff
@@ -1,31 +0,0 @@
// 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.
#import <Foundation/Foundation.h>
@interface FBSDKLikeActionControllerCache : NSObject <NSSecureCoding>
- (instancetype)initWithAccessTokenString:(NSString *)accessTokenString NS_DESIGNATED_INITIALIZER;
@property (nonatomic, copy, readonly) NSString *accessTokenString;
- (id)objectForKeyedSubscript:(id)key;
- (void)resetForAccessTokenString:(NSString *)accessTokenString;
- (void)setObject:(id)object forKeyedSubscript:(id)key;
@end
@@ -1,116 +0,0 @@
// 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.
#import "FBSDKLikeActionControllerCache.h"
#import <UIKit/UIKit.h>
#import "FBSDKLikeActionController.h"
// after 1 day, expire the cached states
#define FBSDK_LIKE_ACTION_CONTROLLER_CACHE_TIMEOUT 60 * 24
#define FBSDK_LIKE_ACTION_CONTROLLER_CACHE_ACCESS_TOKEN_KEY @"accessTokenString"
#define FBSDK_LIKE_ACTION_CONTROLLER_CACHE_ITEMS_KEY @"items"
@implementation FBSDKLikeActionControllerCache
{
NSString *_accessTokenString;
NSMutableDictionary *_items;
}
#pragma mark - Object Lifecycle
- (instancetype)initWithAccessTokenString:(NSString *)accessTokenString
{
if ((self = [super init])) {
_accessTokenString = [accessTokenString copy];
_items = [[NSMutableDictionary alloc] init];
}
return self;
}
- (instancetype)init
{
FBSDK_NOT_DESIGNATED_INITIALIZER(initWithAccessTokenString:);
return [self initWithAccessTokenString:nil];
}
#pragma mark - NSCoding
+ (BOOL)supportsSecureCoding
{
return YES;
}
- (id)initWithCoder:(NSCoder *)decoder
{
NSString *accessTokenString = [decoder decodeObjectOfClass:[NSString class]
forKey:FBSDK_LIKE_ACTION_CONTROLLER_CACHE_ACCESS_TOKEN_KEY];
if ((self = [self initWithAccessTokenString:accessTokenString])) {
NSSet *allowedClasses = [NSSet setWithObjects:[NSDictionary class], [FBSDKLikeActionController class], nil];
NSDictionary *items = [decoder decodeObjectOfClasses:allowedClasses
forKey:FBSDK_LIKE_ACTION_CONTROLLER_CACHE_ITEMS_KEY];
_items = [[NSMutableDictionary alloc] initWithDictionary:items];
[self _prune];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)encoder
{
[encoder encodeObject:_accessTokenString forKey:FBSDK_LIKE_ACTION_CONTROLLER_CACHE_ACCESS_TOKEN_KEY];
[encoder encodeObject:_items forKey:FBSDK_LIKE_ACTION_CONTROLLER_CACHE_ITEMS_KEY];
}
#pragma mark - Public Methods
- (id)objectForKeyedSubscript:(id)key
{
return _items[key];
}
- (void)resetForAccessTokenString:(NSString *)accessTokenString
{
_accessTokenString = [accessTokenString copy];
[_items removeAllObjects];
}
- (void)setObject:(id)object forKeyedSubscript:(id)key
{
_items[key] = object;
}
#pragma mark - Helper Methods
- (void)_prune
{
NSMutableArray *keysToRemove = [[NSMutableArray alloc] init];
[_items enumerateKeysAndObjectsUsingBlock:^(NSString *objectID,
FBSDKLikeActionController *likeActionController,
BOOL *stop) {
NSDate *lastUpdateTime = likeActionController.lastUpdateTime;
if (!lastUpdateTime ||
([[NSDate date] timeIntervalSinceDate:lastUpdateTime] > FBSDK_LIKE_ACTION_CONTROLLER_CACHE_TIMEOUT)) {
[keysToRemove addObject:objectID];
}
}];
[_items removeObjectsForKeys:keysToRemove];
}
@end
@@ -1,33 +0,0 @@
// 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.
#import <UIKit/UIKit.h>
#import "FBSDKLikeBoxView.h"
@interface FBSDKLikeBoxBorderView : UIView
@property (nonatomic, assign) CGFloat borderCornerRadius;
@property (nonatomic, assign) CGFloat borderWidth;
@property (nonatomic, assign) FBSDKLikeBoxCaretPosition caretPosition;
@property (nonatomic, assign, readonly) UIEdgeInsets contentInsets;
@property (nonatomic, strong) UIView *contentView;
@property (nonatomic, strong) UIColor *fillColor;
@property (nonatomic, strong) UIColor *foregroundColor;
@end
@@ -1,323 +0,0 @@
// 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.
#import "FBSDKLikeBoxBorderView.h"
#import "FBSDKCoreKit+Internal.h"
#define FBSDK_LIKE_BOX_BORDER_CARET_WIDTH 6.0
#define FBSDK_LIKE_BOX_BORDER_CARET_HEIGHT 3.0
#define FBSDK_LIKE_BOX_BORDER_CARET_PADDING 3.0
#define FBSDK_LIKE_BOX_BORDER_CONTENT_PADDING 4.0
@implementation FBSDKLikeBoxBorderView
#pragma mark - Object Lifecycle
- (instancetype)initWithFrame:(CGRect)frame
{
if ((self = [super initWithFrame:frame])) {
[self _initializeContent];
}
return self;
}
- (id)initWithCoder:(NSCoder *)decoder
{
if ((self = [super initWithCoder:decoder])) {
[self _initializeContent];
}
return self;
}
#pragma mark - Properties
- (void)setBackgroundColor:(UIColor *)backgroundColor
{
if (![self.backgroundColor isEqual:backgroundColor]) {
[super setBackgroundColor:backgroundColor];
[self setNeedsDisplay];
}
}
- (void)setBorderCornerRadius:(CGFloat)borderCornerRadius
{
if (_borderCornerRadius != borderCornerRadius) {
_borderCornerRadius = borderCornerRadius;
[self setNeedsDisplay];
}
}
- (void)setBorderWidth:(CGFloat)borderWidth
{
if (_borderWidth != borderWidth) {
_borderWidth = borderWidth;
[self setNeedsDisplay];
[self invalidateIntrinsicContentSize];
}
}
- (void)setCaretPosition:(FBSDKLikeBoxCaretPosition)caretPosition
{
if (_caretPosition != caretPosition) {
_caretPosition = caretPosition;
[self setNeedsLayout];
[self setNeedsDisplay];
[self invalidateIntrinsicContentSize];
}
}
- (UIEdgeInsets)contentInsets
{
UIEdgeInsets borderInsets = [self _borderInsets];
return UIEdgeInsetsMake(borderInsets.top + FBSDK_LIKE_BOX_BORDER_CONTENT_PADDING,
borderInsets.left + FBSDK_LIKE_BOX_BORDER_CONTENT_PADDING,
borderInsets.bottom + FBSDK_LIKE_BOX_BORDER_CONTENT_PADDING,
borderInsets.right + FBSDK_LIKE_BOX_BORDER_CONTENT_PADDING);
}
- (void)setContentView:(UIView *)contentView
{
if (_contentView != contentView) {
[_contentView removeFromSuperview];
_contentView = contentView;
[self addSubview:_contentView];
[self setNeedsLayout];
[self invalidateIntrinsicContentSize];
}
}
- (void)setFillColor:(UIColor *)fillColor
{
if (![_fillColor isEqual:fillColor]) {
_fillColor = fillColor;
[self setNeedsDisplay];
}
}
- (void)setForegroundColor:(UIColor *)foregroundColor
{
if (![_foregroundColor isEqual:foregroundColor]) {
_foregroundColor = foregroundColor;
[self setNeedsDisplay];
}
}
#pragma mark - Layout
- (CGSize)intrinsicContentSize
{
return FBSDKEdgeInsetsOutsetSize(self.contentView.intrinsicContentSize, self.contentInsets);
}
- (void)layoutSubviews
{
[super layoutSubviews];
self.contentView.frame = UIEdgeInsetsInsetRect(self.bounds, self.contentInsets);
}
- (CGSize)sizeThatFits:(CGSize)size
{
UIEdgeInsets contentInsets = self.contentInsets;
size = FBSDKEdgeInsetsInsetSize(size, contentInsets);
size = [self.contentView sizeThatFits:size];
size = FBSDKEdgeInsetsOutsetSize(size, contentInsets);
return size;
}
#pragma mark - Drawing
- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSaveGState(context);
// read the configuration properties
CGRect bounds = self.bounds;
CGFloat borderWidth = self.borderWidth;
CGFloat borderCornerRadius = self.borderCornerRadius;
CGFloat contentScaleFactor = self.contentScaleFactor;
// fill the background
if (self.backgroundColor) {
[self.backgroundColor setFill];
CGContextFillRect(context, bounds);
}
// configure the colors and lines
[self.fillColor setFill];
[self.foregroundColor setStroke];
CGContextSetLineJoin(context, kCGLineJoinRound);
CGContextSetLineWidth(context, borderWidth);
// get the frame of the box
CGRect borderFrame = UIEdgeInsetsInsetRect(bounds, [self _borderInsets]);
// define the arcs for the corners
const int start = 0;
const int tangent = 1;
const int end = 2;
CGPoint topLeftArc[3] = {
CGPointMake(CGRectGetMinX(borderFrame) + borderCornerRadius, CGRectGetMinY(borderFrame)),
CGPointMake(CGRectGetMinX(borderFrame), CGRectGetMinY(borderFrame)),
CGPointMake(CGRectGetMinX(borderFrame), CGRectGetMinY(borderFrame) + borderCornerRadius),
};
CGPoint bottomLeftArc[3] = {
CGPointMake(CGRectGetMinX(borderFrame), CGRectGetMaxY(borderFrame) - borderCornerRadius),
CGPointMake(CGRectGetMinX(borderFrame), CGRectGetMaxY(borderFrame)),
CGPointMake(CGRectGetMinX(borderFrame) + borderCornerRadius, CGRectGetMaxY(borderFrame)),
};
CGPoint bottomRightArc[3] = {
CGPointMake(CGRectGetMaxX(borderFrame) - borderCornerRadius, CGRectGetMaxY(borderFrame)),
CGPointMake(CGRectGetMaxX(borderFrame), CGRectGetMaxY(borderFrame)),
CGPointMake(CGRectGetMaxX(borderFrame), CGRectGetMaxY(borderFrame) - borderCornerRadius),
};
CGPoint topRightArc[3] = {
CGPointMake(CGRectGetMaxX(borderFrame), CGRectGetMinY(borderFrame) + borderCornerRadius),
CGPointMake(CGRectGetMaxX(borderFrame), CGRectGetMinY(borderFrame)),
CGPointMake(CGRectGetMaxX(borderFrame) - borderCornerRadius, CGRectGetMinY(borderFrame)),
};
// start a path on the context
CGContextBeginPath(context);
// position the caret and decide which lines to draw
CGPoint caretPoints[3];
switch (self.caretPosition) {
case FBSDKLikeBoxCaretPositionTop:
CGContextMoveToPoint(context, topRightArc[end].x, topRightArc[end].y);
caretPoints[0] = CGPointMake(FBSDKPointsForScreenPixels(floorf, contentScaleFactor, CGRectGetMidX(borderFrame) + (FBSDK_LIKE_BOX_BORDER_CARET_WIDTH / 2)),
CGRectGetMinY(borderFrame));
caretPoints[1] = CGPointMake(FBSDKPointsForScreenPixels(floorf, contentScaleFactor, CGRectGetMidX(borderFrame)),
CGRectGetMinY(borderFrame) - FBSDK_LIKE_BOX_BORDER_CARET_HEIGHT);
caretPoints[2] = CGPointMake(FBSDKPointsForScreenPixels(floorf, contentScaleFactor, CGRectGetMidX(borderFrame) - (FBSDK_LIKE_BOX_BORDER_CARET_WIDTH / 2)),
CGRectGetMinY(borderFrame));
CGContextAddLines(context, caretPoints, sizeof(caretPoints) / sizeof(caretPoints[0]));
CGContextAddArcToPoint(context, topLeftArc[tangent].x, topLeftArc[tangent].y, topLeftArc[end].x, topLeftArc[end].y, borderCornerRadius);
CGContextAddLineToPoint(context, bottomLeftArc[start].x, bottomLeftArc[start].y);
CGContextAddArcToPoint(context, bottomLeftArc[tangent].x, bottomLeftArc[tangent].y, bottomLeftArc[end].x, bottomLeftArc[end].y, borderCornerRadius);
CGContextAddLineToPoint(context, bottomRightArc[start].x, bottomRightArc[start].y);
CGContextAddArcToPoint(context, bottomRightArc[tangent].x, bottomRightArc[tangent].y, bottomRightArc[end].x, bottomRightArc[end].y, borderCornerRadius);
CGContextAddLineToPoint(context, topRightArc[start].x, topRightArc[start].y);
CGContextAddArcToPoint(context, topRightArc[tangent].x, topRightArc[tangent].y, topRightArc[end].x, topRightArc[end].y, borderCornerRadius);
break;
case FBSDKLikeBoxCaretPositionLeft:
CGContextMoveToPoint(context, topLeftArc[end].x, topLeftArc[end].y);
caretPoints[0] = CGPointMake(CGRectGetMinX(borderFrame),
FBSDKPointsForScreenPixels(floorf, contentScaleFactor, CGRectGetMidY(borderFrame) - (FBSDK_LIKE_BOX_BORDER_CARET_WIDTH / 2)));
caretPoints[1] = CGPointMake(CGRectGetMinX(borderFrame) - FBSDK_LIKE_BOX_BORDER_CARET_HEIGHT,
FBSDKPointsForScreenPixels(floorf, contentScaleFactor, CGRectGetMidY(borderFrame)));
caretPoints[2] = CGPointMake(CGRectGetMinX(borderFrame),
FBSDKPointsForScreenPixels(floorf, contentScaleFactor, CGRectGetMidY(borderFrame) + (FBSDK_LIKE_BOX_BORDER_CARET_WIDTH / 2)));
CGContextAddLines(context, caretPoints, sizeof(caretPoints) / sizeof(caretPoints[0]));
CGContextAddArcToPoint(context, bottomLeftArc[tangent].x, bottomLeftArc[tangent].y, bottomLeftArc[end].x, bottomLeftArc[end].y, borderCornerRadius);
CGContextAddLineToPoint(context, bottomRightArc[start].x, bottomRightArc[start].y);
CGContextAddArcToPoint(context, bottomRightArc[tangent].x, bottomRightArc[tangent].y, bottomRightArc[end].x, bottomRightArc[end].y, borderCornerRadius);
CGContextAddLineToPoint(context, topRightArc[start].x, topRightArc[start].y);
CGContextAddArcToPoint(context, topRightArc[tangent].x, topRightArc[tangent].y, topRightArc[end].x, topRightArc[end].y, borderCornerRadius);
CGContextAddLineToPoint(context, topLeftArc[start].x, topLeftArc[start].y);
CGContextAddArcToPoint(context, topLeftArc[tangent].x, topLeftArc[tangent].y, topLeftArc[end].x, topLeftArc[end].y, borderCornerRadius);
break;
case FBSDKLikeBoxCaretPositionBottom:
CGContextMoveToPoint(context, bottomLeftArc[end].x, bottomLeftArc[end].y);
caretPoints[0] = CGPointMake(FBSDKPointsForScreenPixels(floorf, contentScaleFactor, CGRectGetMidX(borderFrame) - (FBSDK_LIKE_BOX_BORDER_CARET_WIDTH / 2)),
CGRectGetMaxY(borderFrame));
caretPoints[1] = CGPointMake(FBSDKPointsForScreenPixels(floorf, contentScaleFactor, CGRectGetMidX(borderFrame)),
CGRectGetMaxY(borderFrame) + FBSDK_LIKE_BOX_BORDER_CARET_HEIGHT);
caretPoints[2] = CGPointMake(FBSDKPointsForScreenPixels(floorf, contentScaleFactor, CGRectGetMidX(borderFrame) + (FBSDK_LIKE_BOX_BORDER_CARET_WIDTH / 2)),
CGRectGetMaxY(borderFrame));
CGContextAddLines(context, caretPoints, sizeof(caretPoints) / sizeof(caretPoints[0]));
CGContextAddArcToPoint(context, bottomRightArc[tangent].x, bottomRightArc[tangent].y, bottomRightArc[end].x, bottomRightArc[end].y, borderCornerRadius);
CGContextAddLineToPoint(context, topRightArc[start].x, topRightArc[start].y);
CGContextAddArcToPoint(context, topRightArc[tangent].x, topRightArc[tangent].y, topRightArc[end].x, topRightArc[end].y, borderCornerRadius);
CGContextAddLineToPoint(context, topLeftArc[start].x, topLeftArc[start].y);
CGContextAddArcToPoint(context, topLeftArc[tangent].x, topLeftArc[tangent].y, topLeftArc[end].x, topLeftArc[end].y, borderCornerRadius);
CGContextAddLineToPoint(context, bottomLeftArc[start].x, bottomLeftArc[start].y);
CGContextAddArcToPoint(context, bottomLeftArc[tangent].x, bottomLeftArc[tangent].y, bottomLeftArc[end].x, bottomLeftArc[end].y, borderCornerRadius);
break;
case FBSDKLikeBoxCaretPositionRight:
CGContextMoveToPoint(context, bottomRightArc[end].x, bottomRightArc[end].y);
caretPoints[0] = CGPointMake(CGRectGetMaxX(borderFrame),
FBSDKPointsForScreenPixels(floorf, contentScaleFactor, CGRectGetMidY(borderFrame) + (FBSDK_LIKE_BOX_BORDER_CARET_WIDTH / 2)));
caretPoints[1] = CGPointMake(CGRectGetMaxX(borderFrame) + FBSDK_LIKE_BOX_BORDER_CARET_HEIGHT,
FBSDKPointsForScreenPixels(floorf, contentScaleFactor, CGRectGetMidY(borderFrame)));
caretPoints[2] = CGPointMake(CGRectGetMaxX(borderFrame),
FBSDKPointsForScreenPixels(floorf, contentScaleFactor, CGRectGetMidY(borderFrame) - (FBSDK_LIKE_BOX_BORDER_CARET_WIDTH / 2)));
CGContextAddLines(context, caretPoints, sizeof(caretPoints) / sizeof(caretPoints[0]));
CGContextAddArcToPoint(context, topRightArc[tangent].x, topRightArc[tangent].y, topRightArc[end].x, topRightArc[end].y, borderCornerRadius);
CGContextAddLineToPoint(context, topLeftArc[start].x, topLeftArc[start].y);
CGContextAddArcToPoint(context, topLeftArc[tangent].x, topLeftArc[tangent].y, topLeftArc[end].x, topLeftArc[end].y, borderCornerRadius);
CGContextAddLineToPoint(context, bottomLeftArc[start].x, bottomLeftArc[start].y);
CGContextAddArcToPoint(context, bottomLeftArc[tangent].x, bottomLeftArc[tangent].y, bottomLeftArc[end].x, bottomLeftArc[end].y, borderCornerRadius);
CGContextAddLineToPoint(context, bottomRightArc[start].x, bottomRightArc[start].y);
CGContextAddArcToPoint(context, bottomRightArc[tangent].x, bottomRightArc[tangent].y, bottomRightArc[end].x, bottomRightArc[end].y, borderCornerRadius);
break;
}
// close and draw now that we have it all
CGContextClosePath(context);
CGContextDrawPath(context, kCGPathFillStroke);
CGContextRestoreGState(context);
}
#pragma mark - Helper Methods
- (UIEdgeInsets)_borderInsets
{
// inset the border bounds by 1/2 of the border width, since it is drawn split between inside and outside of the path
CGFloat scale = self.contentScaleFactor;
CGFloat halfBorderWidth = FBSDKPointsForScreenPixels(ceilf, scale, self.borderWidth / 2);
UIEdgeInsets borderInsets = UIEdgeInsetsMake(halfBorderWidth, halfBorderWidth, halfBorderWidth, halfBorderWidth);
// adjust the insets for the caret position
switch (self.caretPosition) {
case FBSDKLikeBoxCaretPositionTop:{
borderInsets.top += FBSDK_LIKE_BOX_BORDER_CARET_HEIGHT + FBSDK_LIKE_BOX_BORDER_CARET_PADDING;
break;
}
case FBSDKLikeBoxCaretPositionLeft:{
borderInsets.left += FBSDK_LIKE_BOX_BORDER_CARET_HEIGHT + FBSDK_LIKE_BOX_BORDER_CARET_PADDING;
break;
}
case FBSDKLikeBoxCaretPositionBottom:{
borderInsets.bottom += FBSDK_LIKE_BOX_BORDER_CARET_HEIGHT + FBSDK_LIKE_BOX_BORDER_CARET_PADDING;
break;
}
case FBSDKLikeBoxCaretPositionRight:{
borderInsets.right += FBSDK_LIKE_BOX_BORDER_CARET_HEIGHT + FBSDK_LIKE_BOX_BORDER_CARET_PADDING;
break;
}
}
return borderInsets;
}
- (void)_initializeContent
{
self.backgroundColor = [UIColor clearColor];
self.borderCornerRadius = 3.0;
self.borderWidth = 1.0;
self.contentMode = UIViewContentModeRedraw;
self.fillColor = [UIColor whiteColor];
self.foregroundColor = FBSDKUIColorWithRGB(0x6A, 0x71, 0x80);
self.opaque = NO;
}
@end
@@ -1,43 +0,0 @@
// 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.
#import <UIKit/UIKit.h>
/**
NS_ENUM(NSUInteger, FBSDKLikeBoxCaretPosition)
Specifies the position of the caret relative to the box.
*/
typedef NS_ENUM(NSUInteger, FBSDKLikeBoxCaretPosition)
{
/** The caret is on the top of the box. */
FBSDKLikeBoxCaretPositionTop,
/** The caret is on the left of the box. */
FBSDKLikeBoxCaretPositionLeft,
/** The caret is on the bottom of the box. */
FBSDKLikeBoxCaretPositionBottom,
/** The caret is on the right of the box. */
FBSDKLikeBoxCaretPositionRight,
};
@interface FBSDKLikeBoxView : UIView
@property (nonatomic, assign) FBSDKLikeBoxCaretPosition caretPosition;
@property (nonatomic, copy) NSString *text;
@end
@@ -1,108 +0,0 @@
// 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.
#import "FBSDKLikeBoxView.h"
#import "FBSDKCoreKit+Internal.h"
#import "FBSDKLikeBoxBorderView.h"
@implementation FBSDKLikeBoxView
{
FBSDKLikeBoxBorderView *_borderView;
UILabel *_likeCountLabel;
}
#pragma mark - Object Lifecycle
- (instancetype)initWithFrame:(CGRect)frame
{
if ((self = [super initWithFrame:frame])) {
[self _initializeContent];
}
return self;
}
- (id)initWithCoder:(NSCoder *)decoder
{
if ((self = [super initWithCoder:decoder])) {
[self _initializeContent];
}
return self;
}
#pragma mark - Properties
- (void)setCaretPosition:(FBSDKLikeBoxCaretPosition)caretPosition
{
if (_caretPosition != caretPosition) {
_caretPosition = caretPosition;
_borderView.caretPosition = _caretPosition;
[self setNeedsLayout];
[self invalidateIntrinsicContentSize];
}
}
- (NSString *)text
{
return _likeCountLabel.text;
}
- (void)setText:(NSString *)text
{
if (![_likeCountLabel.text isEqualToString:text]) {
_likeCountLabel.text = text;
[self setNeedsLayout];
[self invalidateIntrinsicContentSize];
}
}
#pragma mark - Layout
- (CGSize)intrinsicContentSize
{
return _borderView.intrinsicContentSize;
}
- (void)layoutSubviews
{
[super layoutSubviews];
CGRect bounds = self.bounds;
_borderView.frame = bounds;
}
- (CGSize)sizeThatFits:(CGSize)size
{
return [_borderView sizeThatFits:size];
}
#pragma mark - Helper Methods
- (void)_initializeContent
{
_borderView = [[FBSDKLikeBoxBorderView alloc] initWithFrame:CGRectZero];
[self addSubview:_borderView];
_likeCountLabel = [[UILabel alloc] initWithFrame:CGRectZero];
_likeCountLabel.font = [UIFont systemFontOfSize:11.0];
_likeCountLabel.textAlignment = NSTextAlignmentCenter;
_likeCountLabel.textColor = FBSDKUIColorWithRGB(0x6A, 0x71, 0x80);
_borderView.contentView = _likeCountLabel;
}
@end
@@ -1,29 +0,0 @@
// 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.
#import <Foundation/Foundation.h>
#import "FBSDKCoreKit+Internal.h"
#import "FBSDKLikeActionController.h"
#import "FBSDKLikeButton.h"
@interface FBSDKLikeButton () <FBSDKButtonImpressionTracking>
@property (nonatomic, strong, readwrite) FBSDKLikeActionController *likeActionController;
@end
@@ -1,24 +0,0 @@
// 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.
#import <Foundation/Foundation.h>
#import "FBSDKCoreKit+Internal.h"
@interface FBSDKLikeButtonPopWAV : FBSDKAudioResourceLoader
@end
@@ -1,36 +0,0 @@
// 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.
#import "FBSDKLikeButtonPopWAV.h"
@implementation FBSDKLikeButtonPopWAV
+ (NSString *)name
{
return @"FBSDKLikeButtonPop.wav";
}
+ (NSData *)data
{
const Byte bytes[] = {
0x52, 0x49, 0x46, 0x46, 0xfc, 0x57, 0x02, 0x00, 0x57, 0x41, 0x56, 0x45, 0x4a, 0x55, 0x4e, 0x4b, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x62, 0x65, 0x78, 0x74, 0x5a, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x72, 0x6f, 0x20, 0x54, 0x6f, 0x6f, 0x6c, 0x73, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x59, 0x68, 0x72, 0x72, 0x48, 0x37, 0x38, 0x21, 0x54, 0x66, 0x61, 0x61, 0x61, 0x61, 0x47, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x32, 0x30, 0x31, 0x34, 0x2d, 0x30, 0x31, 0x2d, 0x31, 0x00, 0x31, 0x35, 0x3a, 0x32, 0x38, 0x3a, 0x30, 0x31, 0xf7, 0xa0, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x66, 0x6d, 0x74, 0x20, 0x28, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x80, 0xbb, 0x00, 0x00, 0x00, 0xee, 0x02, 0x00, 0x04, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6d, 0x69, 0x6e, 0x66, 0x10, 0x00, 0x00, 0x00, 0x70, 0xe2, 0xe6, 0xc4, 0xdb, 0x13, 0xcf, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x65, 0x6c, 0x6d, 0x31, 0xd6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0Line truncated
NSUInteger length = sizeof(bytes) / sizeof(Byte);
return [NSData dataWithBytesNoCopy:(void *)bytes length:length freeWhenDone:NO];
}
@end
@@ -1,27 +0,0 @@
// 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.
#import <Foundation/Foundation.h>
#import "FBSDKLikeControl.h"
@interface FBSDKLikeControl ()
- (NSDictionary *)analyticsParameters;
@end
@@ -1,49 +0,0 @@
// 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.
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <FBSDKShareKit/FBSDKLikeObjectType.h>
@protocol FBSDKLikeDialogDelegate;
@interface FBSDKLikeDialog : NSObject
+ (instancetype)likeWithObjectID:(NSString *)objectID
objectType:(FBSDKLikeObjectType)objectType
delegate:(id<FBSDKLikeDialogDelegate>)delegate;
@property (nonatomic, weak) id<FBSDKLikeDialogDelegate> delegate;
@property (nonatomic, copy) NSString *objectID;
@property (nonatomic, assign) FBSDKLikeObjectType objectType;
@property (nonatomic, assign) BOOL shouldFailOnDataError;
@property (nonatomic, weak) UIViewController *fromViewController;
- (BOOL)canLike;
- (BOOL)like;
- (BOOL)validateWithError:(NSError *__autoreleasing *)errorRef;
@end
@protocol FBSDKLikeDialogDelegate <NSObject>
- (void)likeDialog:(FBSDKLikeDialog *)likeDialog didCompleteWithResults:(NSDictionary *)results;
- (void)likeDialog:(FBSDKLikeDialog *)likeDialog didFailWithError:(NSError *)error;
@end
@@ -1,159 +0,0 @@
// 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.
#import "FBSDKLikeDialog.h"
#import "FBSDKCoreKit+Internal.h"
#import "FBSDKShareConstants.h"
#import "FBSDKShareDefines.h"
#import "FBSDKShareError.h"
@implementation FBSDKLikeDialog
#define FBSDK_LIKE_METHOD_MIN_VERSION @"20140410"
#define FBSDK_LIKE_METHOD_NAME @"like"
#define FBSDK_SHARE_RESULT_COMPLETION_GESTURE_VALUE_LIKE @"like"
#define FBSDK_SHARE_RESULT_COMPLETION_GESTURE_VALUE_UNLIKE @"unlike"
#pragma mark - Class Methods
+ (void)initialize
{
if ([FBSDKLikeDialog class] == self) {
[FBSDKServerConfigurationManager loadServerConfigurationWithCompletionBlock:NULL];
}
}
+ (instancetype)likeWithObjectID:(NSString *)objectID
objectType:(FBSDKLikeObjectType)objectType
delegate:(id<FBSDKLikeDialogDelegate>)delegate
{
FBSDKLikeDialog *dialog = [[self alloc] init];
dialog.objectID = objectID;
dialog.objectType = objectType;
dialog.delegate = delegate;
[dialog like];
return dialog;
}
#pragma mark - Public Methods
- (BOOL)canLike
{
return YES;
}
- (BOOL)like
{
NSError *error;
if (![self canLike]) {
error = [FBSDKShareError errorWithCode:FBSDKShareDialogNotAvailableErrorCode
message:@"Like dialog is not available."];
[_delegate likeDialog:self didFailWithError:error];
return NO;
}
if (![self validateWithError:&error]) {
[_delegate likeDialog:self didFailWithError:error];
return NO;
}
NSMutableDictionary *parameters = [[NSMutableDictionary alloc] init];
[FBSDKInternalUtility dictionary:parameters setObject:self.objectID forKey:@"object_id"];
[FBSDKInternalUtility dictionary:parameters
setObject:NSStringFromFBSDKLikeObjectType(self.objectType)
forKey:@"object_type"];
FBSDKBridgeAPIRequest * webRequest = [FBSDKBridgeAPIRequest bridgeAPIRequestWithProtocolType:FBSDKBridgeAPIProtocolTypeWeb
scheme:FBSDK_SHARE_JS_DIALOG_SCHEME
methodName:FBSDK_LIKE_METHOD_NAME
methodVersion:nil
parameters:parameters
userInfo:nil];
FBSDKBridgeAPICallbackBlock completionBlock = ^(FBSDKBridgeAPIResponse *response) {
[self _handleCompletionWithDialogResults:response.responseParameters error:response.error];
};
FBSDKServerConfiguration *configuration = [FBSDKServerConfigurationManager cachedServerConfiguration];
BOOL useSafariViewController = [configuration useSafariViewControllerForDialogName:FBSDKDialogConfigurationNameLike];
if ([self _canLikeNative]) {
FBSDKBridgeAPIRequest *nativeRequest = [FBSDKBridgeAPIRequest bridgeAPIRequestWithProtocolType:FBSDKBridgeAPIProtocolTypeNative
scheme:FBSDK_CANOPENURL_FACEBOOK
methodName:FBSDK_LIKE_METHOD_NAME
methodVersion:FBSDK_LIKE_METHOD_MIN_VERSION
parameters:parameters
userInfo:nil];
void (^networkCompletionBlock)(FBSDKBridgeAPIResponse *) = ^(FBSDKBridgeAPIResponse *response) {
if (response.error.code == FBSDKAppVersionUnsupportedErrorCode) {
[[FBSDKApplicationDelegate sharedInstance] openBridgeAPIRequest:webRequest
useSafariViewController:useSafariViewController
fromViewController:self.fromViewController
completionBlock:completionBlock];
} else {
completionBlock(response);
}
};
[[FBSDKApplicationDelegate sharedInstance] openBridgeAPIRequest:nativeRequest
useSafariViewController:useSafariViewController
fromViewController:self.fromViewController
completionBlock:networkCompletionBlock];
} else {
[[FBSDKApplicationDelegate sharedInstance] openBridgeAPIRequest:webRequest
useSafariViewController:useSafariViewController
fromViewController:self.fromViewController
completionBlock:completionBlock];
}
return YES;
}
- (BOOL)validateWithError:(NSError *__autoreleasing *)errorRef
{
if (![self.objectID length]) {
if (errorRef != NULL) {
*errorRef = [FBSDKShareError requiredArgumentErrorWithName:@"objectID" message:nil];
}
return NO;
}
if (errorRef != NULL) {
*errorRef = nil;
}
return YES;
}
#pragma mark - Helper Methods
- (BOOL)_canLikeNative
{
FBSDKServerConfiguration *configuration = [FBSDKServerConfigurationManager cachedServerConfiguration];
BOOL useNativeDialog = [configuration useNativeDialogForDialogName:FBSDKDialogConfigurationNameLike];
return (useNativeDialog && [FBSDKInternalUtility isFacebookAppInstalled]);
}
- (void)_handleCompletionWithDialogResults:(NSDictionary *)results error:(NSError *)error
{
if (!_delegate) {
return;
}
NSString *completionGesture = results[FBSDK_SHARE_RESULT_COMPLETION_GESTURE_KEY];
if (completionGesture && !error) {
[_delegate likeDialog:self didCompleteWithResults:[results copy]];
} else {
[_delegate likeDialog:self didFailWithError:error];
}
}
@end
Loaded 100 of 466 files, more files were not shown because too many files have changed in this diff. Show more