-
Notifications
You must be signed in to change notification settings - Fork 0
/
ChildBrowserCommand.m
executable file
·87 lines (66 loc) · 2.59 KB
/
ChildBrowserCommand.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
75
76
77
78
79
80
81
82
83
84
85
86
87
// Created by Jesse MacFadyen on 10-05-29.
// Copyright 2010 Nitobi. All rights reserved.
// Copyright 2012, Randy McMillan
#import "ChildBrowserCommand.h"
#import <Cordova/CDVViewController.h>
#import <AVFoundation/AVFoundation.h>
@implementation ChildBrowserCommand
@synthesize childBrowser;
- (void)showWebPage:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options // args: url
{
/* setting audio session category to "Playback" (since iOS 6) */
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
NSError *setCategoryError = nil;
BOOL ok = [audioSession setCategory:AVAudioSessionCategoryPlayback error:&setCategoryError];
if (!ok) {
NSLog(@"Error setting AVAudioSessionCategoryPlayback: %@", setCategoryError);
};
if (self.childBrowser == nil) {
#if __has_feature(objc_arc)
self.childBrowser = [[ChildBrowserViewController alloc] initWithScale:NO];
#else
self.childBrowser = [[[ChildBrowserViewController alloc] initWithScale:NO] autorelease];
#endif
self.childBrowser.delegate = self;
self.childBrowser.orientationDelegate = self.viewController;
}
/* // TODO: Work in progress
NSString* strOrientations = [ options objectForKey:@"supportedOrientations"];
NSArray* supportedOrientations = [strOrientations componentsSeparatedByString:@","];
*/
[self.viewController presentModalViewController:childBrowser animated:YES];
NSString* url = (NSString*)[arguments objectAtIndex:0];
[self.childBrowser loadURL:url];
}
- (void)getPage:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
{
NSString* url = (NSString*)[arguments objectAtIndex:0];
[self.childBrowser loadURL:url];
}
- (void)close:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options // args: url
{
[self.childBrowser closeBrowser];
}
- (void)onClose
{
[self.webView stringByEvaluatingJavaScriptFromString:@"window.plugins.childBrowser.onClose();"];
}
- (void)onOpenInSafari
{
[self.webView stringByEvaluatingJavaScriptFromString:@"window.plugins.childBrowser.onOpenExternal();"];
}
- (void)onChildLocationChange:(NSString*)newLoc
{
NSString* tempLoc = [NSString stringWithFormat:@"%@", newLoc];
NSString* encUrl = [tempLoc stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString* jsCallback = [NSString stringWithFormat:@"window.plugins.childBrowser.onLocationChange('%@');", encUrl];
[self.webView stringByEvaluatingJavaScriptFromString:jsCallback];
}
#if !__has_feature(objc_arc)
- (void)dealloc
{
self.childBrowser = nil;
[super dealloc];
}
#endif
@end