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

Commit

Permalink
Updated iOS ChildBrowser: 1. Fixed iOS 6 orientation issue, 2. ARC/no…
Browse files Browse the repository at this point in the history
…n-ARC compatibility 3. Uncrustified
  • Loading branch information
shazron committed Sep 21, 2012
1 parent 911d3d7 commit d4ce61d
Show file tree
Hide file tree
Showing 4 changed files with 198 additions and 197 deletions.
15 changes: 4 additions & 11 deletions iOS/ChildBrowser/ChildBrowserCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,14 @@
// Copyright 2010 Nitobi. All rights reserved.
// Copyright 2012, Randy McMillan


#import <Cordova/CDVPlugin.h>
#import "ChildBrowserViewController.h"

@interface ChildBrowserCommand : CDVPlugin <ChildBrowserDelegate>{}

@property (nonatomic, strong) ChildBrowserViewController* childBrowser;

@interface ChildBrowserCommand : CDVPlugin <ChildBrowserDelegate> {

ChildBrowserViewController* childBrowser;
}

@property (nonatomic, retain) ChildBrowserViewController *childBrowser;


- (void) showWebPage:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
-(void) onChildLocationChange:(NSString*)newLoc;
- (void)showWebPage:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
- (void)onChildLocationChange:(NSString*)newLoc;

@end
66 changes: 37 additions & 29 deletions iOS/ChildBrowser/ChildBrowserCommand.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,66 +5,74 @@
#import "ChildBrowserCommand.h"
#import <Cordova/CDVViewController.h>



@implementation ChildBrowserCommand

@synthesize childBrowser;

- (void) showWebPage:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options // args: url
- (void)showWebPage:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options // args: url
{
if(childBrowser == NULL)
{
childBrowser = [[ ChildBrowserViewController alloc ] initWithScale:FALSE ];
childBrowser.delegate = self;
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:@","];
*/

CDVViewController* cont = (CDVViewController*)[ super viewController ];
childBrowser.supportedOrientations = cont.supportedOrientations;
[ cont presentModalViewController:childBrowser animated:YES ];
[self.viewController presentModalViewController:childBrowser animated:YES];

NSString *url = (NSString*) [arguments objectAtIndex:0];
NSString* url = (NSString*)[arguments objectAtIndex:0];

[childBrowser loadURL:url ];

}
- (void) getPage:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options {
NSString *url = (NSString*) [arguments objectAtIndex:0];
[childBrowser loadURL:url ];
[self.childBrowser loadURL:url];
}

-(void) close:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options // args: url
- (void)getPage:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
{
[ childBrowser closeBrowser];
NSString* url = (NSString*)[arguments objectAtIndex:0];

[self.childBrowser loadURL:url];
}

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

-(void) onOpenInSafari
- (void)onClose
{
NSString* jsCallback = [NSString stringWithFormat:@"window.plugins.childBrowser.onOpenExternal();",@""];
[self.webView stringByEvaluatingJavaScriptFromString:jsCallback];
[self.webView stringByEvaluatingJavaScriptFromString:@"window.plugins.childBrowser.onClose();"];
}


-(void) onChildLocationChange:(NSString*)newLoc
- (void)onOpenInSafari
{
[self.webView stringByEvaluatingJavaScriptFromString:@"window.plugins.childBrowser.onOpenExternal();"];
}

NSString* tempLoc = [NSString stringWithFormat:@"%@",newLoc];
- (void)onChildLocationChange:(NSString*)newLoc
{
NSString* tempLoc = [NSString stringWithFormat:@"%@", newLoc];
NSString* encUrl = [tempLoc stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

NSString* jsCallback = [NSString stringWithFormat:@"window.plugins.childBrowser.onLocationChange('%@');",encUrl];
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
60 changes: 32 additions & 28 deletions iOS/ChildBrowser/ChildBrowserViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,51 @@

#import <UIKit/UIKit.h>

@protocol ChildBrowserDelegate<NSObject>

@protocol ChildBrowserDelegate <NSObject>

/*
* onChildLocationChanging:newLoc
*
* Discussion:
* Invoked when a new page has loaded
*/
-(void) onChildLocationChange:(NSString*)newLoc;
-(void) onOpenInSafari;
-(void) onClose;
- (void)onChildLocationChange:(NSString*)newLoc;
- (void)onOpenInSafari;
- (void)onClose;

@end

@protocol CDVOrientationDelegate <NSObject>

- (NSUInteger)supportedInterfaceOrientations;
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation;
- (BOOL)shouldAutorotate;

@end

@interface ChildBrowserViewController : UIViewController <UIWebViewDelegate>{}

@property (nonatomic, strong) IBOutlet UIWebView* webView;
@property (nonatomic, strong) IBOutlet UIBarButtonItem* closeBtn;
@property (nonatomic, strong) IBOutlet UIBarButtonItem* refreshBtn;
@property (nonatomic, strong) IBOutlet UILabel* addressLabel;
@property (nonatomic, strong) IBOutlet UIBarButtonItem* backBtn;
@property (nonatomic, strong) IBOutlet UIBarButtonItem* fwdBtn;
@property (nonatomic, strong) IBOutlet UIBarButtonItem* safariBtn;
@property (nonatomic, strong) IBOutlet UIActivityIndicatorView* spinner;

// unsafe_unretained is equivalent to assign - used to prevent retain cycles in the two properties below
@property (nonatomic, unsafe_unretained) id <ChildBrowserDelegate> delegate;
@property (nonatomic, unsafe_unretained) id orientationDelegate;

@property (copy) NSString* imageURL;
@property (assign) BOOL isImage;
@property (assign) BOOL scaleEnabled;

@interface ChildBrowserViewController : UIViewController < UIWebViewDelegate > {
IBOutlet UIWebView* webView;
IBOutlet UIBarButtonItem* closeBtn;
IBOutlet UIBarButtonItem* refreshBtn;
IBOutlet UILabel* addressLabel;
IBOutlet UIBarButtonItem* backBtn;
IBOutlet UIBarButtonItem* fwdBtn;
IBOutlet UIBarButtonItem* safariBtn;
IBOutlet UIActivityIndicatorView* spinner;
BOOL scaleEnabled;
BOOL isImage;
NSString* imageURL;
NSArray* supportedOrientations;
id <ChildBrowserDelegate> delegate;
}

@property (nonatomic, retain)id <ChildBrowserDelegate> delegate;
@property (nonatomic, retain) NSArray* supportedOrientations;
@property(retain) NSString* imageURL;
@property(assign) BOOL isImage;

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation;
- (ChildBrowserViewController*)initWithScale:(BOOL)enabled;
- (IBAction)onDoneButtonPress:(id)sender;
- (IBAction)onSafariButtonPress:(id)sender;
- (void)loadURL:(NSString*)url;
-(void)closeBrowser;
- (void)closeBrowser;

@end
Loading

0 comments on commit d4ce61d

Please sign in to comment.