-
Notifications
You must be signed in to change notification settings - Fork 110
/
Copy pathSafariViewManager.m
43 lines (34 loc) · 1.28 KB
/
SafariViewManager.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
#import "SafariViewManager.h"
#import "RCTUtils.h"
#import "RCTLog.h"
@implementation SafariViewManager
RCT_EXPORT_MODULE()
RCT_EXPORT_METHOD(show:(NSDictionary *)args callback:(RCTResponseSenderBlock)callback)
{
// Error if no url is passed
if (!args[@"url"]) {
RCTLogError(@"[SafariView] You must specify a url.");
return;
}
// Initialize the Safari View
SFSafariViewController *safariView = [[SFSafariViewController alloc] initWithURL:[NSURL URLWithString:args[@"url"]] entersReaderIfAvailable:args[@"readerMode"]];
safariView.delegate = self;
// Display the Safari View
UIViewController *ctrl = [[[[UIApplication sharedApplication] delegate] window] rootViewController];
[ctrl presentViewController:safariView animated:YES completion:nil];
}
RCT_EXPORT_METHOD(isAvailable:(RCTResponseSenderBlock)callback)
{
if ([SFSafariViewController class]) {
// SafariView is available
return callback(@[[NSNull null], @true]);
} else {
return callback(@[RCTMakeError(@"SafariView is unavailable.", nil, nil)]);
}
}
-(void)safariViewControllerDidFinish:(nonnull SFSafariViewController *)controller
{
[controller dismissViewControllerAnimated:true completion:nil];
NSLog(@"SafariView dismissed.");
}
@end