Skip to content
This repository was archived by the owner on Apr 29, 2021. It is now read-only.

Commit d4ce61d

Browse files
committed
Updated iOS ChildBrowser: 1. Fixed iOS 6 orientation issue, 2. ARC/non-ARC compatibility 3. Uncrustified
1 parent 911d3d7 commit d4ce61d

File tree

4 files changed

+198
-197
lines changed

4 files changed

+198
-197
lines changed

iOS/ChildBrowser/ChildBrowserCommand.h

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,14 @@
22
// Copyright 2010 Nitobi. All rights reserved.
33
// Copyright 2012, Randy McMillan
44

5-
65
#import <Cordova/CDVPlugin.h>
76
#import "ChildBrowserViewController.h"
87

8+
@interface ChildBrowserCommand : CDVPlugin <ChildBrowserDelegate>{}
99

10+
@property (nonatomic, strong) ChildBrowserViewController* childBrowser;
1011

11-
@interface ChildBrowserCommand : CDVPlugin <ChildBrowserDelegate> {
12-
13-
ChildBrowserViewController* childBrowser;
14-
}
15-
16-
@property (nonatomic, retain) ChildBrowserViewController *childBrowser;
17-
18-
19-
- (void) showWebPage:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
20-
-(void) onChildLocationChange:(NSString*)newLoc;
12+
- (void)showWebPage:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
13+
- (void)onChildLocationChange:(NSString*)newLoc;
2114

2215
@end

iOS/ChildBrowser/ChildBrowserCommand.m

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,66 +5,74 @@
55
#import "ChildBrowserCommand.h"
66
#import <Cordova/CDVViewController.h>
77

8-
9-
108
@implementation ChildBrowserCommand
119

1210
@synthesize childBrowser;
1311

14-
- (void) showWebPage:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options // args: url
12+
- (void)showWebPage:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options // args: url
1513
{
16-
if(childBrowser == NULL)
17-
{
18-
childBrowser = [[ ChildBrowserViewController alloc ] initWithScale:FALSE ];
19-
childBrowser.delegate = self;
14+
if (self.childBrowser == nil) {
15+
#if __has_feature(objc_arc)
16+
self.childBrowser = [[ChildBrowserViewController alloc] initWithScale:NO];
17+
#else
18+
self.childBrowser = [[[ChildBrowserViewController alloc] initWithScale:NO] autorelease];
19+
#endif
20+
self.childBrowser.delegate = self;
21+
self.childBrowser.orientationDelegate = self.viewController;
2022
}
2123

2224
/* // TODO: Work in progress
2325
NSString* strOrientations = [ options objectForKey:@"supportedOrientations"];
2426
NSArray* supportedOrientations = [strOrientations componentsSeparatedByString:@","];
2527
*/
2628

27-
CDVViewController* cont = (CDVViewController*)[ super viewController ];
28-
childBrowser.supportedOrientations = cont.supportedOrientations;
29-
[ cont presentModalViewController:childBrowser animated:YES ];
29+
[self.viewController presentModalViewController:childBrowser animated:YES];
3030

31-
NSString *url = (NSString*) [arguments objectAtIndex:0];
31+
NSString* url = (NSString*)[arguments objectAtIndex:0];
3232

33-
[childBrowser loadURL:url ];
34-
35-
}
36-
- (void) getPage:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options {
37-
NSString *url = (NSString*) [arguments objectAtIndex:0];
38-
[childBrowser loadURL:url ];
33+
[self.childBrowser loadURL:url];
3934
}
4035

41-
-(void) close:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options // args: url
36+
- (void)getPage:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
4237
{
43-
[ childBrowser closeBrowser];
38+
NSString* url = (NSString*)[arguments objectAtIndex:0];
4439

40+
[self.childBrowser loadURL:url];
4541
}
4642

47-
-(void) onClose
43+
- (void)close:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options // args: url
4844
{
49-
NSString* jsCallback = [NSString stringWithFormat:@"window.plugins.childBrowser.onClose();",@""];
50-
[self.webView stringByEvaluatingJavaScriptFromString:jsCallback];
45+
[self.childBrowser closeBrowser];
5146
}
5247

53-
-(void) onOpenInSafari
48+
- (void)onClose
5449
{
55-
NSString* jsCallback = [NSString stringWithFormat:@"window.plugins.childBrowser.onOpenExternal();",@""];
56-
[self.webView stringByEvaluatingJavaScriptFromString:jsCallback];
50+
[self.webView stringByEvaluatingJavaScriptFromString:@"window.plugins.childBrowser.onClose();"];
5751
}
5852

59-
60-
-(void) onChildLocationChange:(NSString*)newLoc
53+
- (void)onOpenInSafari
6154
{
55+
[self.webView stringByEvaluatingJavaScriptFromString:@"window.plugins.childBrowser.onOpenExternal();"];
56+
}
6257

63-
NSString* tempLoc = [NSString stringWithFormat:@"%@",newLoc];
58+
- (void)onChildLocationChange:(NSString*)newLoc
59+
{
60+
NSString* tempLoc = [NSString stringWithFormat:@"%@", newLoc];
6461
NSString* encUrl = [tempLoc stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
6562

66-
NSString* jsCallback = [NSString stringWithFormat:@"window.plugins.childBrowser.onLocationChange('%@');",encUrl];
63+
NSString* jsCallback = [NSString stringWithFormat:@"window.plugins.childBrowser.onLocationChange('%@');", encUrl];
64+
6765
[self.webView stringByEvaluatingJavaScriptFromString:jsCallback];
66+
}
67+
6868

69+
#if !__has_feature(objc_arc)
70+
- (void)dealloc
71+
{
72+
self.childBrowser = nil;
73+
74+
[super dealloc];
6975
}
76+
#endif
77+
7078
@end

iOS/ChildBrowser/ChildBrowserViewController.h

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,47 +4,51 @@
44

55
#import <UIKit/UIKit.h>
66

7-
@protocol ChildBrowserDelegate<NSObject>
8-
7+
@protocol ChildBrowserDelegate <NSObject>
98

109
/*
1110
* onChildLocationChanging:newLoc
1211
*
1312
* Discussion:
1413
* Invoked when a new page has loaded
1514
*/
16-
-(void) onChildLocationChange:(NSString*)newLoc;
17-
-(void) onOpenInSafari;
18-
-(void) onClose;
15+
- (void)onChildLocationChange:(NSString*)newLoc;
16+
- (void)onOpenInSafari;
17+
- (void)onClose;
18+
1919
@end
2020

21+
@protocol CDVOrientationDelegate <NSObject>
22+
23+
- (NSUInteger)supportedInterfaceOrientations;
24+
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation;
25+
- (BOOL)shouldAutorotate;
26+
27+
@end
28+
29+
@interface ChildBrowserViewController : UIViewController <UIWebViewDelegate>{}
30+
31+
@property (nonatomic, strong) IBOutlet UIWebView* webView;
32+
@property (nonatomic, strong) IBOutlet UIBarButtonItem* closeBtn;
33+
@property (nonatomic, strong) IBOutlet UIBarButtonItem* refreshBtn;
34+
@property (nonatomic, strong) IBOutlet UILabel* addressLabel;
35+
@property (nonatomic, strong) IBOutlet UIBarButtonItem* backBtn;
36+
@property (nonatomic, strong) IBOutlet UIBarButtonItem* fwdBtn;
37+
@property (nonatomic, strong) IBOutlet UIBarButtonItem* safariBtn;
38+
@property (nonatomic, strong) IBOutlet UIActivityIndicatorView* spinner;
39+
40+
// unsafe_unretained is equivalent to assign - used to prevent retain cycles in the two properties below
41+
@property (nonatomic, unsafe_unretained) id <ChildBrowserDelegate> delegate;
42+
@property (nonatomic, unsafe_unretained) id orientationDelegate;
43+
44+
@property (copy) NSString* imageURL;
45+
@property (assign) BOOL isImage;
46+
@property (assign) BOOL scaleEnabled;
2147

22-
@interface ChildBrowserViewController : UIViewController < UIWebViewDelegate > {
23-
IBOutlet UIWebView* webView;
24-
IBOutlet UIBarButtonItem* closeBtn;
25-
IBOutlet UIBarButtonItem* refreshBtn;
26-
IBOutlet UILabel* addressLabel;
27-
IBOutlet UIBarButtonItem* backBtn;
28-
IBOutlet UIBarButtonItem* fwdBtn;
29-
IBOutlet UIBarButtonItem* safariBtn;
30-
IBOutlet UIActivityIndicatorView* spinner;
31-
BOOL scaleEnabled;
32-
BOOL isImage;
33-
NSString* imageURL;
34-
NSArray* supportedOrientations;
35-
id <ChildBrowserDelegate> delegate;
36-
}
37-
38-
@property (nonatomic, retain)id <ChildBrowserDelegate> delegate;
39-
@property (nonatomic, retain) NSArray* supportedOrientations;
40-
@property(retain) NSString* imageURL;
41-
@property(assign) BOOL isImage;
42-
43-
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation;
4448
- (ChildBrowserViewController*)initWithScale:(BOOL)enabled;
4549
- (IBAction)onDoneButtonPress:(id)sender;
4650
- (IBAction)onSafariButtonPress:(id)sender;
4751
- (void)loadURL:(NSString*)url;
48-
-(void)closeBrowser;
52+
- (void)closeBrowser;
4953

5054
@end

0 commit comments

Comments
 (0)