0

I have a phonegap/cordova app and when I call the ChildBrowser from the app, exit the childbrowser, and go back to app, the webview goes under status bar.

There are a million answers as to how to prevent webview (in iOS7 and later) from going under status bar. That is not the issue here because initially the app is fine and its webview is not overlapping with the status bar.

The issue happens only after exiting the childbrowser.

Basic flow: Launch app (all is fine) -> call ChildBrowser (from app) -> Exit ChildBrowser -> back to app (PROBLEM: webview under status bar).

Please ask for clarifications and please advise.

AppDelegate.m

/*
 Licensed to the Apache Software Foundation (ASF) under one
...
 */

//
//  AppDelegate.m

#import "AppDelegate.h"
#import "MainViewController.h"

#ifdef CORDOVA_FRAMEWORK
    #import <Cordova/CDVPlugin.h>
    #import <Cordova/CDVURLProtocol.h>
#else
    #import "CDVPlugin.h"
    #import "CDVURLProtocol.h"
#endif

@implementation AppDelegate
@synthesize window, viewController;

- (id) init
{   
    /** If you need to do any extra app-specific initialization, you can do it here
     *  -jm
     **/
    NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage]; 
    [cookieStorage setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways];         
    [CDVURLProtocol registerURLProtocol];

    return [super init];
}

#pragma UIApplicationDelegate implementation

/**
 * This is main kick off after the app inits, the views and Settings are setup here. (preferred - iOS4 and up)
 */
- (BOOL) application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{    
    NSURL* url = [launchOptions objectForKey:UIApplicationLaunchOptionsURLKey];
    NSString* invokeString = nil;

    if (url && [url isKindOfClass:[NSURL class]]) {
        invokeString = [url absoluteString];
        NSLog(@"ios-cordova-childbrowser launchOptions = %@", url);
    }    

    CGRect screenBounds = [[UIScreen mainScreen] bounds];
    self.window = [[[UIWindow alloc] initWithFrame:screenBounds] autorelease];
    self.window.autoresizesSubviews = YES;

    CGRect viewBounds = [[UIScreen mainScreen] applicationFrame];

    self.viewController = [[[MainViewController alloc] init] autorelease];
    self.viewController.useSplashScreen = YES;
    self.viewController.wwwFolderName = @"www";
    self.viewController.startPage = @"index.html";
    self.viewController.invokeString = invokeString;
    self.viewController.view.frame = viewBounds;

    // check whether the current orientation is supported: if it is, keep it, rather than forcing a rotation
    BOOL forceStartupRotation = YES;
    UIDeviceOrientation curDevOrientation = [[UIDevice currentDevice] orientation];

    if (UIDeviceOrientationUnknown == curDevOrientation) {
        // UIDevice isn't firing orientation notifications yet… go look at the status bar
        curDevOrientation = (UIDeviceOrientation)[[UIApplication sharedApplication] statusBarOrientation];
    }

    if (UIDeviceOrientationIsValidInterfaceOrientation(curDevOrientation)) {
        for (NSNumber *orient in self.viewController.supportedOrientations) {
            if ([orient intValue] == curDevOrientation) {
                forceStartupRotation = NO;
                break;
            }
        }
    } 

    if (forceStartupRotation) {
        NSLog(@"supportedOrientations: %@", self.viewController.supportedOrientations);
        // The first item in the supportedOrientations array is the start orientation (guaranteed to be at least Portrait)
        UIInterfaceOrientation newOrient = [[self.viewController.supportedOrientations objectAtIndex:0] intValue];
        NSLog(@"AppDelegate forcing status bar to: %d from: %d", newOrient, curDevOrientation);
        [[UIApplication sharedApplication] setStatusBarOrientation:newOrient];
    }

    NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:0 diskCapacity:0 diskPath:nil];
    [NSURLCache setSharedURLCache:sharedCache];
    [sharedCache release];

    [self.window addSubview:self.viewController.view];
    [self.window makeKeyAndVisible];

    [[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleBlackTranslucent];

    return YES;
}

// this happens while we are running ( in the background, or from within our own app )
// only valid if ios-cordova-childbrowser-Info.plist specifies a protocol to handle
- (BOOL) application:(UIApplication*)application handleOpenURL:(NSURL*)url 
{
    if (!url) { 
        return NO; 
    }

    // calls into javascript global function 'handleOpenURL'
    NSString* jsString = [NSString stringWithFormat:@"handleOpenURL(\"%@\");", url];
    [self.viewController.webView stringByEvaluatingJavaScriptFromString:jsString];

    // all plugins will get the notification, and their handlers will be called 
    [[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:CDVPluginHandleOpenURLNotification object:url]];

    return YES;    
}

- (void) dealloc
{
    [super dealloc];
}

- (void)setOrientation:(NSMutableArray *)arguments
{
    NSLog(@"setting orientation");
    MainViewController *vc = self.viewController;
    [vc setDevideDirection:2];
    //self.viewController.supportedOrientations = arguments;
    //self.viewController.supportedOrientations = arguments;
}
@end
2MB
  • 1
  • 2
  • Can you show the code you're using to initially keep the web view below the status bar? – Tim May 24 '15 at 02:49
  • @Tim: I've done nothing in particular. The status bar wasn't overlaying with the view. Another programmer added this to change the text color of the status bar to white: [[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleBlackTranslucent]; I've posted the entire AppDelegate.m – 2MB May 24 '15 at 04:39
  • try switching from childbrowser to inAppBrowser, childbrowser was replaced by inAppBrowser long time ago – jcesarmobile May 25 '15 at 08:40

0 Answers0