This repository has been archived by the owner on Jun 15, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathUtils.m
42 lines (35 loc) · 1.53 KB
/
Utils.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
//
// Utils.m
// AVPlayerExample
//
// Copyright © 2016-2017 Twilio, Inc. All rights reserved.
//
#import "Utils.h"
@implementation PlatformUtils
+ (BOOL)isSimulator {
#if TARGET_IPHONE_SIMULATOR
return YES;
#endif
return NO;
}
@end
@implementation TokenUtils
+ (void)retrieveAccessTokenFromURL:(NSString *)tokenURLStr
completion:(void (^)(NSString* token, NSError *err)) completionHandler {
NSURL *tokenURL = [NSURL URLWithString:tokenURLStr];
NSURLSessionConfiguration *sessionConfig = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfig];
NSURLSessionDataTask *task = [session dataTaskWithURL:tokenURL
completionHandler: ^(NSData * _Nullable data,
NSURLResponse * _Nullable response,
NSError * _Nullable error) {
NSString *accessToken = nil;
if (!error && data) {
accessToken = [[NSString alloc] initWithData:data
encoding:NSUTF8StringEncoding];
}
completionHandler(accessToken, error);
}];
[task resume];
}
@end