This repository was archived by the owner on Jun 14, 2024. It is now read-only.
forked from azendoo/react-native-onepassword
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOnePassword.m
More file actions
44 lines (36 loc) · 1.36 KB
/
OnePassword.m
File metadata and controls
44 lines (36 loc) · 1.36 KB
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
#import "OnePassword.h"
#import "OnePasswordExtension.h"
#import <React/RCTUtils.h>
#import <LocalAuthentication/LocalAuthentication.h>
#import <React/RCTUIManager.h>
@implementation OnePassword
RCT_EXPORT_MODULE();
RCT_EXPORT_METHOD(isSupported: (RCTResponseSenderBlock)callback)
{
if ([[OnePasswordExtension sharedExtension] isAppExtensionAvailable]) {
callback(@[[NSNull null], @true]);
}
else {
callback(@[RCTMakeError(@"OnePassword is not supported.", nil, nil)]);
return;
}
}
RCT_EXPORT_METHOD(findLogin: (NSString *)url
callback: (RCTResponseSenderBlock)callback)
{
UIViewController *controller = RCTPresentedViewController();
dispatch_async(dispatch_get_main_queue(), ^{
[[OnePasswordExtension sharedExtension] findLoginForURLString:url
forViewController:controller sender:nil completion:^(NSDictionary *loginDictionary, NSError *error) {
if (loginDictionary.count == 0) {
callback(@[RCTMakeError(@"Error while getting login credentials.", nil, nil)]);
return;
}
callback(@[[NSNull null], @{
@"username": loginDictionary[AppExtensionUsernameKey],
@"password": loginDictionary[AppExtensionPasswordKey]
}]);
}];
});
}
@end