forked from parse-community/Parse-SDK-iOS-OSX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPFCloud.m
74 lines (58 loc) · 2.56 KB
/
PFCloud.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/**
* Copyright (c) 2015-present, Parse, LLC.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#import "PFCloud.h"
#import "BFTask+Private.h"
#import "PFCloudCodeController.h"
#import "PFCommandResult.h"
#import "PFCoreManager.h"
#import "PFUserPrivate.h"
#import "Parse_Private.h"
@implementation PFCloud
///--------------------------------------
#pragma mark - Public
///--------------------------------------
+ (BFTask *)callFunctionInBackground:(NSString *)functionName withParameters:(NSDictionary *)parameters {
return [[PFUser _getCurrentUserSessionTokenAsync] continueWithBlock:^id(BFTask *task) {
NSString *sessionToken = task.result;
PFCloudCodeController *controller = [Parse _currentManager].coreManager.cloudCodeController;
return [controller callCloudCodeFunctionAsync:functionName
withParameters:parameters
sessionToken:sessionToken];
}];
}
+ (void)callFunctionInBackground:(NSString *)function
withParameters:(NSDictionary *)parameters
block:(PFIdResultBlock)block {
[[self callFunctionInBackground:function withParameters:parameters] thenCallBackOnMainThreadAsync:block];
}
@end
///--------------------------------------
#pragma mark - Synchronous
///--------------------------------------
@implementation PFCloud (Synchronous)
+ (id)callFunction:(NSString *)function withParameters:(NSDictionary *)parameters {
return [self callFunction:function withParameters:parameters error:nil];
}
+ (id)callFunction:(NSString *)function withParameters:(NSDictionary *)parameters error:(NSError **)error {
return [[self callFunctionInBackground:function withParameters:parameters] waitForResult:error];
}
@end
///--------------------------------------
#pragma mark - Deprecated
///--------------------------------------
@implementation PFCloud (Deprecated)
+ (void)callFunctionInBackground:(NSString *)function
withParameters:(nullable NSDictionary *)parameters
target:(nullable id)target
selector:(nullable SEL)selector {
[self callFunctionInBackground:function withParameters:parameters block:^(id results, NSError *error) {
[PFInternalUtils safePerformSelector:selector withTarget:target object:results object:error];
}];
}
@end