- update
This commit is contained in:
1 parent
1bf4b9ef1d
commit
4e66c377fd
664 files changed
+14818
-10172
No files matched your search
+32
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
/**
|
||||
Returns whether all instances of `BFTask` should automatically @try/@catch exceptions in continuation blocks. Default: `YES`.
|
||||
|
||||
@return Boolean value indicating whether exceptions are being caught.
|
||||
*/
|
||||
extern BOOL BFTaskCatchesExceptions(void)
|
||||
__attribute__((deprecated("This is temporary API and will be removed in a future release.")));
|
||||
|
||||
/**
|
||||
Set whether all instances of `BFTask` should automatically @try/@catch exceptions in continuation blocks. Default: `YES`.
|
||||
|
||||
@param catchExceptions Boolean value indicating whether exceptions shoudl be caught.
|
||||
*/
|
||||
extern void BFTaskSetCatchesExceptions(BOOL catchExceptions)
|
||||
__attribute__((deprecated("This is a temporary API and will be removed in a future release.")));
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
#import "BFTask+Exceptions.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
static BOOL taskCatchExceptions = YES;
|
||||
|
||||
BOOL BFTaskCatchesExceptions(void) {
|
||||
return taskCatchExceptions;
|
||||
}
|
||||
|
||||
void BFTaskSetCatchesExceptions(BOOL catchExceptions) {
|
||||
taskCatchExceptions = catchExceptions;
|
||||
}
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
Generated
+17
-5
@@ -26,8 +26,11 @@ extern NSInteger const kBFMultipleErrorsError;
|
||||
|
||||
/*!
|
||||
An exception that is thrown if there was multiple exceptions on <BFTask taskForCompletionOfAllTasks:>.
|
||||
|
||||
@deprecated `BFTask` exception handling is deprecated and will be removed in a future release.
|
||||
*/
|
||||
extern NSString *const BFTaskMultipleExceptionsException;
|
||||
extern NSString *const BFTaskMultipleExceptionsException
|
||||
__attribute__((deprecated("`BFTask` exception handling is deprecated and will be removed in a future release.")));
|
||||
|
||||
/*!
|
||||
An error userInfo key used if there were multiple errors on <BFTask taskForCompletionOfAllTasks:>.
|
||||
@@ -38,8 +41,11 @@ extern NSString *const BFTaskMultipleErrorsUserInfoKey;
|
||||
/*!
|
||||
An error userInfo key used if there were multiple exceptions on <BFTask taskForCompletionOfAllTasks:>.
|
||||
Value type is `NSArray<NSException *> *`.
|
||||
|
||||
@deprecated `BFTask` exception handling is deprecated and will be removed in a future release.
|
||||
*/
|
||||
extern NSString *const BFTaskMultipleExceptionsUserInfoKey;
|
||||
extern NSString *const BFTaskMultipleExceptionsUserInfoKey
|
||||
__attribute__((deprecated("`BFTask` exception handling is deprecated and will be removed in a future release.")));
|
||||
|
||||
@class BFExecutor;
|
||||
@class BFTask;
|
||||
@@ -54,7 +60,7 @@ extern NSString *const BFTaskMultipleExceptionsUserInfoKey;
|
||||
/*!
|
||||
A block that can act as a continuation for a task.
|
||||
*/
|
||||
typedef __nullable id(^BFContinuationBlock)(BFTask<ResultType> *task);
|
||||
typedef __nullable id(^BFContinuationBlock)(BFTask<ResultType> *t);
|
||||
|
||||
/*!
|
||||
Creates a task that is already completed with the given result.
|
||||
@@ -71,8 +77,11 @@ typedef __nullable id(^BFContinuationBlock)(BFTask<ResultType> *task);
|
||||
/*!
|
||||
Creates a task that is already completed with the given exception.
|
||||
@param exception The exception for the task.
|
||||
|
||||
@deprecated `BFTask` exception handling is deprecated and will be removed in a future release.
|
||||
*/
|
||||
+ (instancetype)taskWithException:(NSException *)exception;
|
||||
+ (instancetype)taskWithException:(NSException *)exception
|
||||
__attribute__((deprecated("`BFTask` exception handling is deprecated and will be removed in a future release.")));
|
||||
|
||||
/*!
|
||||
Creates a task that is already cancelled.
|
||||
@@ -143,8 +152,11 @@ typedef __nullable id(^BFContinuationBlock)(BFTask<ResultType> *task);
|
||||
|
||||
/*!
|
||||
The exception of a failed task.
|
||||
|
||||
@deprecated `BFTask` exception handling is deprecated and will be removed in a future release.
|
||||
*/
|
||||
@property (nullable, nonatomic, strong, readonly) NSException *exception;
|
||||
@property (nullable, nonatomic, strong, readonly) NSException *exception
|
||||
__attribute__((deprecated("`BFTask` exception handling is deprecated and will be removed in a future release.")));
|
||||
|
||||
/*!
|
||||
Whether this task has been cancelled.
|
||||
|
||||
Generated
+54
-26
@@ -13,6 +13,7 @@
|
||||
#import <libkern/OSAtomic.h>
|
||||
|
||||
#import "Bolts.h"
|
||||
#import "BFTask+Exceptions.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@@ -126,30 +127,35 @@ NSString *const BFTaskMultipleExceptionsUserInfoKey = @"exceptions";
|
||||
|
||||
BFTaskCompletionSource *tcs = [BFTaskCompletionSource taskCompletionSource];
|
||||
for (BFTask *task in tasks) {
|
||||
[task continueWithBlock:^id(BFTask *task) {
|
||||
if (task.exception) {
|
||||
[task continueWithBlock:^id(BFTask *t) {
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
if (t.exception) {
|
||||
@synchronized (lock) {
|
||||
[exceptions addObject:task.exception];
|
||||
[exceptions addObject:t.exception];
|
||||
#pragma clang diagnostic pop
|
||||
}
|
||||
} else if (task.error) {
|
||||
} else if (t.error) {
|
||||
@synchronized (lock) {
|
||||
[errors addObject:task.error];
|
||||
[errors addObject:t.error];
|
||||
}
|
||||
} else if (task.cancelled) {
|
||||
} else if (t.cancelled) {
|
||||
OSAtomicIncrement32Barrier(&cancelled);
|
||||
}
|
||||
|
||||
if (OSAtomicDecrement32Barrier(&total) == 0) {
|
||||
if (exceptions.count > 0) {
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
if (exceptions.count == 1) {
|
||||
tcs.exception = [exceptions firstObject];
|
||||
} else {
|
||||
NSException *exception =
|
||||
[NSException exceptionWithName:BFTaskMultipleExceptionsException
|
||||
reason:@"There were multiple exceptions."
|
||||
userInfo:@{ BFTaskMultipleExceptionsUserInfoKey: exceptions }];
|
||||
NSException *exception = [NSException exceptionWithName:BFTaskMultipleExceptionsException
|
||||
reason:@"There were multiple exceptions."
|
||||
userInfo:@{ BFTaskMultipleExceptionsUserInfoKey: exceptions }];
|
||||
tcs.exception = exception;
|
||||
}
|
||||
#pragma clang diagnostic pop
|
||||
} else if (errors.count > 0) {
|
||||
if (errors.count == 1) {
|
||||
tcs.error = [errors firstObject];
|
||||
@@ -193,20 +199,23 @@ NSString *const BFTaskMultipleExceptionsUserInfoKey = @"exceptions";
|
||||
|
||||
BFTaskCompletionSource *source = [BFTaskCompletionSource taskCompletionSource];
|
||||
for (BFTask *task in tasks) {
|
||||
[task continueWithBlock:^id(BFTask *task) {
|
||||
if (task.exception != nil) {
|
||||
[task continueWithBlock:^id(BFTask *t) {
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
if (t.exception != nil) {
|
||||
@synchronized(lock) {
|
||||
[exceptions addObject:task.exception];
|
||||
[exceptions addObject:t.exception];
|
||||
#pragma clang diagnostic pop
|
||||
}
|
||||
} else if (task.error != nil) {
|
||||
} else if (t.error != nil) {
|
||||
@synchronized(lock) {
|
||||
[errors addObject:task.error];
|
||||
[errors addObject:t.error];
|
||||
}
|
||||
} else if (task.cancelled) {
|
||||
} else if (t.cancelled) {
|
||||
OSAtomicIncrement32Barrier(&cancelled);
|
||||
} else {
|
||||
if(OSAtomicCompareAndSwap32Barrier(0, 1, &completed)) {
|
||||
[source setResult:task.result];
|
||||
[source setResult:t.result];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -215,14 +224,16 @@ NSString *const BFTaskMultipleExceptionsUserInfoKey = @"exceptions";
|
||||
if (cancelled > 0) {
|
||||
[source cancel];
|
||||
} else if (exceptions.count > 0) {
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
if (exceptions.count == 1) {
|
||||
source.exception = exceptions.firstObject;
|
||||
} else {
|
||||
NSException *exception =
|
||||
[NSException exceptionWithName:BFTaskMultipleExceptionsException
|
||||
reason:@"There were multiple exceptions."
|
||||
userInfo:@{ @"exceptions": exceptions }];
|
||||
NSException *exception = [NSException exceptionWithName:BFTaskMultipleExceptionsException
|
||||
reason:@"There were multiple exceptions."
|
||||
userInfo:@{ BFTaskMultipleExceptionsUserInfoKey: exceptions }];
|
||||
source.exception = exception;
|
||||
#pragma clang diagnostic pop
|
||||
}
|
||||
} else if (errors.count > 0) {
|
||||
if (errors.count == 1) {
|
||||
@@ -394,20 +405,33 @@ NSString *const BFTaskMultipleExceptionsUserInfoKey = @"exceptions";
|
||||
}
|
||||
|
||||
id result = nil;
|
||||
@try {
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
if (BFTaskCatchesExceptions()) {
|
||||
@try {
|
||||
result = block(self);
|
||||
} @catch (NSException *exception) {
|
||||
NSLog(@"[Bolts] Warning: `BFTask` caught an exception in the continuation block."
|
||||
@" This behavior is discouraged and will be removed in a future release."
|
||||
@" Caught Exception: %@", exception);
|
||||
tcs.exception = exception;
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
result = block(self);
|
||||
} @catch (NSException *exception) {
|
||||
tcs.exception = exception;
|
||||
return;
|
||||
}
|
||||
#pragma clang diagnostic pop
|
||||
|
||||
if ([result isKindOfClass:[BFTask class]]) {
|
||||
|
||||
id (^setupWithTask) (BFTask *) = ^id(BFTask *task) {
|
||||
if (cancellationToken.cancellationRequested || task.cancelled) {
|
||||
[tcs cancel];
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
} else if (task.exception) {
|
||||
tcs.exception = task.exception;
|
||||
#pragma clang diagnostic pop
|
||||
} else if (task.error) {
|
||||
tcs.error = task.error;
|
||||
} else {
|
||||
@@ -499,7 +523,11 @@ NSString *const BFTaskMultipleExceptionsUserInfoKey = @"exceptions";
|
||||
}
|
||||
[self.condition lock];
|
||||
}
|
||||
[self.condition wait];
|
||||
// TODO: (nlutsenko) Restructure this to use Bolts-Swift thread access synchronization architecture
|
||||
// In the meantime, it's absolutely safe to get `_completed` aka an ivar, as long as it's a `BOOL` aka less than word size.
|
||||
while (!_completed) {
|
||||
[self.condition wait];
|
||||
}
|
||||
[self.condition unlock];
|
||||
}
|
||||
|
||||
|
||||
+8
-2
@@ -49,8 +49,11 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
Completes the task by setting an exception.
|
||||
Attempting to set this for a completed task will raise an exception.
|
||||
@param exception The exception for the task.
|
||||
|
||||
@deprecated `BFTask` exception handling is deprecated and will be removed in a future release.
|
||||
*/
|
||||
- (void)setException:(NSException *)exception;
|
||||
- (void)setException:(NSException *)exception
|
||||
__attribute__((deprecated("`BFTask` exception handling is deprecated and will be removed in a future release.")));
|
||||
|
||||
/*!
|
||||
Completes the task by marking it as cancelled.
|
||||
@@ -75,8 +78,11 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
Sets the exception of the task if it wasn't already completed.
|
||||
@param exception The exception for the task.
|
||||
@returns whether the new value was set.
|
||||
|
||||
@deprecated `BFTask` exception handling is deprecated and will be removed in a future release.
|
||||
*/
|
||||
- (BOOL)trySetException:(NSException *)exception;
|
||||
- (BOOL)trySetException:(NSException *)exception
|
||||
__attribute__((deprecated("`BFTask` exception handling is deprecated and will be removed in a future release.")));
|
||||
|
||||
/*!
|
||||
Sets the cancellation state of the task if it wasn't already completed.
|
||||
|
||||
Generated
+1
@@ -13,6 +13,7 @@
|
||||
#import <Bolts/BFCancellationTokenSource.h>
|
||||
#import <Bolts/BFExecutor.h>
|
||||
#import <Bolts/BFTask.h>
|
||||
#import <Bolts/BFTask+Exceptions.h>
|
||||
#import <Bolts/BFTaskCompletionSource.h>
|
||||
|
||||
#if __has_include(<Bolts/BFAppLink.h>) && TARGET_OS_IPHONE && !TARGET_OS_WATCH && !TARGET_OS_TV
|
||||
|
||||
Generated
+1
-1
@@ -12,6 +12,6 @@
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
NSString *const BoltsFrameworkVersionString = @"1.7.0";
|
||||
NSString *const BoltsFrameworkVersionString = @"1.8.4";
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
+20
@@ -57,6 +57,12 @@ typedef NS_ENUM(NSInteger, BFAppLinkNavigationType) {
|
||||
extras:(NSDictionary *)extras
|
||||
appLinkData:(NSDictionary *)appLinkData;
|
||||
|
||||
/*!
|
||||
Creates an NSDictionary with the correct format for iOS callback URLs,
|
||||
to be used as 'appLinkData' argument in the call to navigationWithAppLink:extras:appLinkData:
|
||||
*/
|
||||
+ (NSDictionary *)callbackAppLinkDataForAppWithName:(NSString *)appName url:(NSString *)url;
|
||||
|
||||
/*! Performs the navigation */
|
||||
- (BFAppLinkNavigationType)navigate:(NSError **)error;
|
||||
|
||||
@@ -69,6 +75,20 @@ typedef NS_ENUM(NSInteger, BFAppLinkNavigationType) {
|
||||
/*! Navigates to a BFAppLink and returns whether it opened in-app or in-browser */
|
||||
+ (BFAppLinkNavigationType)navigateToAppLink:(BFAppLink *)link error:(NSError **)error;
|
||||
|
||||
/*!
|
||||
Returns a BFAppLinkNavigationType based on a BFAppLink.
|
||||
It's essentially a no-side-effect version of navigateToAppLink:error:,
|
||||
allowing apps to determine flow based on the link type (e.g. open an
|
||||
internal web view instead of going straight to the browser for regular links.)
|
||||
*/
|
||||
+ (BFAppLinkNavigationType)navigationTypeForLink:(BFAppLink *)link;
|
||||
|
||||
/*!
|
||||
Return navigation type for current instance.
|
||||
No-side-effect version of navigate:
|
||||
*/
|
||||
- (BFAppLinkNavigationType)navigationType;
|
||||
|
||||
/*! Navigates to a URL (an asynchronous action) and returns a BFNavigationType */
|
||||
+ (BFTask *)navigateToURLInBackground:(NSURL *)destination;
|
||||
|
||||
|
||||
+42
-1
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "BFAppLinkNavigation.h"
|
||||
|
||||
#import <Bolts/Bolts.h>
|
||||
|
||||
@@ -20,6 +20,9 @@ FOUNDATION_EXPORT NSString *const BFAppLinkTargetKeyName;
|
||||
FOUNDATION_EXPORT NSString *const BFAppLinkUserAgentKeyName;
|
||||
FOUNDATION_EXPORT NSString *const BFAppLinkExtrasKeyName;
|
||||
FOUNDATION_EXPORT NSString *const BFAppLinkVersionKeyName;
|
||||
FOUNDATION_EXPORT NSString *const BFAppLinkRefererAppLink;
|
||||
FOUNDATION_EXPORT NSString *const BFAppLinkRefererAppName;
|
||||
FOUNDATION_EXPORT NSString *const BFAppLinkRefererUrl;
|
||||
|
||||
static id<BFAppLinkResolving> defaultResolver;
|
||||
|
||||
@@ -43,6 +46,10 @@ static id<BFAppLinkResolving> defaultResolver;
|
||||
return navigation;
|
||||
}
|
||||
|
||||
+ (NSDictionary *)callbackAppLinkDataForAppWithName:(NSString *)appName url:(NSString *)url {
|
||||
return @{BFAppLinkRefererAppLink: @{BFAppLinkRefererAppName: appName, BFAppLinkRefererUrl: url}};
|
||||
}
|
||||
|
||||
- (NSString *)stringByEscapingQueryString:(NSString *)string {
|
||||
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_7_0 || __MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_10_9
|
||||
return [string stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
|
||||
@@ -229,6 +236,40 @@ static id<BFAppLinkResolving> defaultResolver;
|
||||
appLinkData:nil] navigate:error];
|
||||
}
|
||||
|
||||
+ (BFAppLinkNavigationType)navigationTypeForLink:(BFAppLink *)link {
|
||||
return [[self navigationWithAppLink:link extras:nil appLinkData:nil] navigationType];
|
||||
}
|
||||
|
||||
- (BFAppLinkNavigationType)navigationType {
|
||||
BFAppLinkTarget *eligibleTarget = nil;
|
||||
for (BFAppLinkTarget *target in self.appLink.targets) {
|
||||
if ([[UIApplication sharedApplication] canOpenURL:target.URL]) {
|
||||
eligibleTarget = target;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (eligibleTarget != nil) {
|
||||
NSURL *appLinkURL = [self appLinkURLWithTargetURL:eligibleTarget.URL error:nil];
|
||||
if (appLinkURL != nil) {
|
||||
return BFAppLinkNavigationTypeApp;
|
||||
} else {
|
||||
return BFAppLinkNavigationTypeFailure;
|
||||
}
|
||||
}
|
||||
|
||||
if (self.appLink.webURL != nil) {
|
||||
NSURL *appLinkURL = [self appLinkURLWithTargetURL:eligibleTarget.URL error:nil];
|
||||
if (appLinkURL != nil) {
|
||||
return BFAppLinkNavigationTypeBrowser;
|
||||
} else {
|
||||
return BFAppLinkNavigationTypeFailure;
|
||||
}
|
||||
}
|
||||
|
||||
return BFAppLinkNavigationTypeFailure;
|
||||
}
|
||||
|
||||
+ (id<BFAppLinkResolving>)defaultResolver {
|
||||
if (defaultResolver) {
|
||||
return defaultResolver;
|
||||
|
||||
Generated
+4
-4
@@ -55,11 +55,11 @@
|
||||
NSString *refererAppName = refererAppLink[BFAppLinkRefererAppName];
|
||||
|
||||
if (refererURLString && refererAppName) {
|
||||
BFAppLinkTarget *target = [BFAppLinkTarget appLinkTargetWithURL:[NSURL URLWithString:refererURLString]
|
||||
appStoreId:nil
|
||||
appName:refererAppName];
|
||||
BFAppLinkTarget *appLinkTarget = [BFAppLinkTarget appLinkTargetWithURL:[NSURL URLWithString:refererURLString]
|
||||
appStoreId:nil
|
||||
appName:refererAppName];
|
||||
_appLinkReferer = [BFAppLink appLinkWithSourceURL:[NSURL URLWithString:refererURLString]
|
||||
targets:@[ target ]
|
||||
targets:@[ appLinkTarget ]
|
||||
webURL:nil
|
||||
isBackToReferrer:YES];
|
||||
}
|
||||
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Reference in new issue
Block a user