Skip to content

Commit cf5d44e

Browse files
Supports Accounts.framework.
1 parent e78716e commit cf5d44e

17 files changed

Lines changed: 352 additions & 9 deletions
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// ACAccountStore+JavaScriptBridge.h
3+
// JavaScriptBridge
4+
//
5+
// Created by kishikawa katsumi on 2014/01/05.
6+
// Copyright (c) 2014 kishikawa katsumi. All rights reserved.
7+
//
8+
9+
#import <Accounts/Accounts.h>
10+
11+
@interface ACAccountStore (JavaScriptBridge)
12+
13+
@end
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
//
2+
// ACAccountStore+JavaScriptBridge.m
3+
// JavaScriptBridge
4+
//
5+
// Created by kishikawa katsumi on 2014/01/05.
6+
// Copyright (c) 2014 kishikawa katsumi. All rights reserved.
7+
//
8+
9+
#import "ACAccountStore+JavaScriptBridge.h"
10+
#import "JSBMessageForwarding.h"
11+
12+
@implementation ACAccountStore (JavaScriptBridge)
13+
14+
#pragma clang diagnostic push
15+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
16+
17+
- (void)__saveAccount:(ACAccount *)account withCompletionHandler:(JSValue *)handlerFunction
18+
{
19+
JSContext *context = [JSContext currentContext];
20+
id currentSelf = context[@"self"];
21+
22+
ACAccountStoreSaveCompletionHandler completionHandler = NULL;
23+
if (!handlerFunction.isUndefined) {
24+
completionHandler = ^(BOOL success, NSError *error) {
25+
NSMutableArray *parameters = [[NSMutableArray alloc] init];
26+
[parameters addObject:@(success)];
27+
if (error) {
28+
[parameters addObject:error];
29+
} else {
30+
[parameters addObject:[NSNull null]];
31+
}
32+
33+
dispatchFunction(currentSelf, handlerFunction, parameters);
34+
};
35+
}
36+
37+
[self saveAccount:account withCompletionHandler:completionHandler];
38+
}
39+
40+
- (void)__requestAccessToAccountsWithType:(ACAccountType *)accountType
41+
withCompletionHandler:(JSValue *)handlerFunction
42+
{
43+
JSContext *context = [JSContext currentContext];
44+
id currentSelf = context[@"self"];
45+
46+
ACAccountStoreRequestAccessCompletionHandler handler = NULL;
47+
if (!handlerFunction.isUndefined) {
48+
handler = ^(BOOL granted, NSError *error) {
49+
NSMutableArray *parameters = [[NSMutableArray alloc] init];
50+
[parameters addObject:@(granted)];
51+
if (error) {
52+
[parameters addObject:error];
53+
} else {
54+
[parameters addObject:[NSNull null]];
55+
}
56+
57+
dispatchFunction(currentSelf, handlerFunction, parameters);
58+
};
59+
}
60+
61+
[self requestAccessToAccountsWithType:accountType withCompletionHandler:handler];
62+
}
63+
64+
- (void)__requestAccessToAccountsWithType:(ACAccountType *)accountType
65+
options:(NSDictionary *)options
66+
completion:(JSValue *)completionFunction
67+
{
68+
JSContext *context = [JSContext currentContext];
69+
id currentSelf = context[@"self"];
70+
71+
ACAccountStoreRequestAccessCompletionHandler completion = NULL;
72+
if (!completionFunction.isUndefined) {
73+
completion = ^(BOOL granted, NSError *error) {
74+
NSMutableArray *parameters = [[NSMutableArray alloc] init];
75+
[parameters addObject:@(granted)];
76+
if (error) {
77+
[parameters addObject:error];
78+
} else {
79+
[parameters addObject:[NSNull null]];
80+
}
81+
82+
dispatchFunction(currentSelf, completionFunction, parameters);
83+
};
84+
}
85+
86+
[self requestAccessToAccountsWithType:accountType options:options completion:completion];
87+
}
88+
89+
- (void)__renewCredentialsForAccount:(ACAccount *)account completion:(JSValue *)handlerFunction
90+
{
91+
JSContext *context = [JSContext currentContext];
92+
id currentSelf = context[@"self"];
93+
94+
ACAccountStoreCredentialRenewalHandler completionHandler = NULL;
95+
if (!handlerFunction.isUndefined) {
96+
completionHandler = ^(ACAccountCredentialRenewResult renewResult, NSError *error) {
97+
NSMutableArray *parameters = [[NSMutableArray alloc] init];
98+
[parameters addObject:@(renewResult)];
99+
if (error) {
100+
[parameters addObject:error];
101+
} else {
102+
[parameters addObject:[NSNull null]];
103+
}
104+
105+
dispatchFunction(currentSelf, handlerFunction, parameters);
106+
};
107+
}
108+
109+
[self renewCredentialsForAccount:account completion:completionHandler];
110+
}
111+
112+
- (void)__removeAccount:(ACAccount *)account withCompletionHandler:(JSValue *)handlerFunction
113+
{
114+
JSContext *context = [JSContext currentContext];
115+
id currentSelf = context[@"self"];
116+
117+
ACAccountStoreRemoveCompletionHandler completionHandler = NULL;
118+
if (!handlerFunction.isUndefined) {
119+
completionHandler = ^(BOOL success, NSError *error) {
120+
NSMutableArray *parameters = [[NSMutableArray alloc] init];
121+
[parameters addObject:@(success)];
122+
if (error) {
123+
[parameters addObject:error];
124+
} else {
125+
[parameters addObject:[NSNull null]];
126+
}
127+
128+
dispatchFunction(currentSelf, handlerFunction, parameters);
129+
};
130+
}
131+
132+
[self removeAccount:account withCompletionHandler:completionHandler];
133+
}
134+
135+
#pragma clang diagnostic pop
136+
137+
@end

Classes/Private/ALAssetsGroup+JavaScriptBridge.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// JavaScriptBridge
44
//
55
// Created by kishikawa katsumi on 2014/01/05.
6-
// Copyright (c) 2014年 kishikawa katsumi. All rights reserved.
6+
// Copyright (c) 2014 kishikawa katsumi. All rights reserved.
77
//
88

99
#import <AssetsLibrary/AssetsLibrary.h>

Classes/Private/ALAssetsGroup+JavaScriptBridge.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// JavaScriptBridge
44
//
55
// Created by kishikawa katsumi on 2014/01/05.
6-
// Copyright (c) 2014年 kishikawa katsumi. All rights reserved.
6+
// Copyright (c) 2014 kishikawa katsumi. All rights reserved.
77
//
88

99
#import "ALAssetsGroup+JavaScriptBridge.h"

Classes/Private/JSBMessageForwarding.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// JavaScriptBridge
44
//
55
// Created by kishikawa katsumi on 2014/01/05.
6-
// Copyright (c) 2014年 kishikawa katsumi. All rights reserved.
6+
// Copyright (c) 2014 kishikawa katsumi. All rights reserved.
77
//
88

99
#import "JSBMessageForwarding.h"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// SLComposeViewController+JavaScriptBridge.h
3+
// JavaScriptBridge
4+
//
5+
// Created by kishikawa katsumi on 2014/01/05.
6+
// Copyright (c) 2014 kishikawa katsumi. All rights reserved.
7+
//
8+
9+
#import <Social/Social.h>
10+
11+
@interface SLComposeViewController (JavaScriptBridge)
12+
13+
@end
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// SLComposeViewController+JavaScriptBridge.m
3+
// JavaScriptBridge
4+
//
5+
// Created by kishikawa katsumi on 2014/01/05.
6+
// Copyright (c) 2014 kishikawa katsumi. All rights reserved.
7+
//
8+
9+
#import "SLComposeViewController+JavaScriptBridge.h"
10+
11+
@implementation SLComposeViewController (JavaScriptBridge)
12+
13+
@end
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// SLRequest+JavaScriptBridge.h
3+
// JavaScriptBridge
4+
//
5+
// Created by kishikawa katsumi on 2014/01/05.
6+
// Copyright (c) 2014 kishikawa katsumi. All rights reserved.
7+
//
8+
9+
#import <Social/Social.h>
10+
11+
@interface SLRequest (JavaScriptBridge)
12+
13+
@end
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//
2+
// SLRequest+JavaScriptBridge.m
3+
// JavaScriptBridge
4+
//
5+
// Created by kishikawa katsumi on 2014/01/05.
6+
// Copyright (c) 2014 kishikawa katsumi. All rights reserved.
7+
//
8+
9+
#import "SLRequest+JavaScriptBridge.h"
10+
#import "JSBMessageForwarding.h"
11+
12+
@implementation SLRequest (JavaScriptBridge)
13+
14+
- (void)__performRequestWithHandler:(JSValue *)handlerFunction
15+
{
16+
JSContext *context = [JSContext currentContext];
17+
id currentSelf = context[@"self"];
18+
19+
SLRequestHandler handler = NULL;
20+
if (!handlerFunction.isUndefined) {
21+
handler = ^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
22+
NSMutableArray *parameters = [[NSMutableArray alloc] init];
23+
if (responseData) {
24+
[parameters addObject:responseData];
25+
} else {
26+
[parameters addObject:[NSNull null]];
27+
}
28+
if (urlResponse) {
29+
[parameters addObject:urlResponse];
30+
} else {
31+
[parameters addObject:[NSNull null]];
32+
}
33+
if (error) {
34+
[parameters addObject:error];
35+
} else {
36+
[parameters addObject:[NSNull null]];
37+
}
38+
39+
dispatchFunction(currentSelf, handlerFunction, parameters);
40+
};
41+
}
42+
43+
[self performRequestWithHandler:handler];
44+
}
45+
46+
@end

Classes/iOS/FrameworkSupport/Accounts/JSBACAccountStore.h

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,18 @@
1616
- (ACAccount *)accountWithIdentifier:(NSString *)identifier;
1717
- (ACAccountType *)accountTypeWithAccountTypeIdentifier:(NSString *)typeIdentifier;
1818
- (NSArray *)accountsWithAccountType:(ACAccountType *)accountType;
19-
- (void)saveAccount:(ACAccount *)account withCompletionHandler:(ACAccountStoreSaveCompletionHandler)completionHandler;
20-
- (void)requestAccessToAccountsWithType:(ACAccountType *)accountType withCompletionHandler:(ACAccountStoreRequestAccessCompletionHandler)handler;
21-
- (void)requestAccessToAccountsWithType:(ACAccountType *)accountType options:(NSDictionary *)options completion:(ACAccountStoreRequestAccessCompletionHandler)completion;
22-
- (void)renewCredentialsForAccount:(ACAccount *)account completion:(ACAccountStoreCredentialRenewalHandler)completionHandler;
23-
- (void)removeAccount:(ACAccount *)account withCompletionHandler:(ACAccountStoreRemoveCompletionHandler)completionHandler;
19+
JSExportAs(saveAccountWithCompletionHandler,
20+
- (void)__saveAccount:(ACAccount *)account withCompletionHandler:(JSValue *)completionHandler);
21+
JSExportAs(requestAccessToAccountsWithTypeWithCompletionHandler,
22+
- (void)__requestAccessToAccountsWithType:(ACAccountType *)accountType withCompletionHandler:(JSValue *)handler);
23+
JSExportAs(requestAccessToAccountsWithTypeOptionsCompletion,
24+
- (void)__requestAccessToAccountsWithType:(ACAccountType *)accountType
25+
options:(NSDictionary *)options
26+
completion:(JSValue *)completion);
27+
JSExportAs(renewCredentialsForAccountCompletion,
28+
- (void)renewCredentialsForAccount:(ACAccount *)account completion:(JSValue *)completionHandler);
29+
JSExportAs(removeAccountWithCompletionHandler,
30+
- (void)removeAccount:(ACAccount *)account withCompletionHandler:(JSValue *)completionHandler);
2431

2532
#pragma clang diagnostic pop
2633

0 commit comments

Comments
 (0)