1

My Cordova 3.6 app has been using the StatusBar plugin fine, when compiled using Xcode 5. I call StatusBar.hide() to hide the statusbar for the entire app, and again after executing plugins like Camera.

However after upgrading to Xcode 6 (for iOS 8 compatibility), the status bar doesn't hide properly in iOS8. I managed to partially fix it by setting "UIViewControllerBasedStatusBarAppearance" to "YES" at the Xcode Info.plist to let the StatusBar plugin to take control.

But, plugins like Camera now automatically show status bar when selecting photo from album. I have to again call StatusBar.hide after selecting a photo to hide the bar again.

Previously when I compiled in Xcode 5 and ran it in iOS8, it's fine. The problem only appeared after I upgraded Xcode (and probably the iOS base kit to 8.1 together). I've also tried updating the Camera and Statusbar plugins.

How to I permanently disable the status bar for my app, and make it hidden even when selecting photos from album?

Thank you.

Mayank Jain
  • 5,663
  • 7
  • 32
  • 65
Mongrel Jedi
  • 747
  • 2
  • 7
  • 22

2 Answers2

0

So I managed to hide the status bar in my app without using the toolbar anymore. What I am using and suggest you use is hooks.

Here is what I am doing:

In project folder i have the following directories:

  • _hook_extras
  • hooks
  • merges
  • platforms
  • plugins
  • res
  • www

within the _hook_extras folder i have an ios subdirectory. within that folder is my Project-Info.plist.

inside my plist file I have added this:

<key>UIStatusBarHidden</key>
<true/>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>

In my hooks folder i have a subdirectory called before_compile. within that is a js file that uses the following code to copy the plist into the project on compile.

!/usr/bin/env node



var fs = require('fs');
var path = require('path');
var exec = require('child_process').exec;

// no need to configure below
var rootdir = process.argv[2];


var filestocopy = [ {
    "_hook_extras/ios/Project-Info.plist": "platforms/ios/Project/Project-Info.plist"
}

filestocopy.forEach(function (obj) {
    Object.keys(obj).forEach(function (key) {
        var val = obj[key];
        var srcfile = path.join(rootdir, key);
        var destfile = path.join(rootdir, val);


        // check if the file is a directory
        if (fs.statSync(srcfile).isDirectory()) {


            // make the directory if necessary?
            child = exec("mkdir -p " + destfile, function (error, stdout, stderr) {
                if (error) {
                    console.log(error);
                } else {
                    console.log('Directory ' + destfile + ' created.');
                }

                // copy the files to the destination directory
                child = exec("cp -r " + srcfile + " " + destfile, function (error, stdout, stderr) {
                    if (error !== null) {
                        console.log("exec error: " + error);
                    } else {
                        console.log("copied " + srcfile + " to " + destfile);
                    }
                });
            });

        } else {

            console.log("copying " + srcfile + " to " + destfile);
            var destdir = path.dirname(destfile);
            if (fs.existsSync(srcfile) && fs.existsSync(destdir)) {
                fs.createReadStream(srcfile).pipe(
                    fs.createWriteStream(destfile));
            }
        }
    });
});
Gchorba
  • 301
  • 2
  • 13
  • Thank you for your suggestion. My project actually has not problem hiding the status bar, but rather, it appears to be affecting the Cordova plugins that I'm relying on that makes use of camera / photo album, such as the Camera and QR Code plugins. When those plugins are in use, the status bar appears, and I have to manually call the StatusBar plugin to deactivated it again after the plugin is used. The thing is it only affects the app when it is compiled with the new Xcode 6, but not when I compiled it on Xcode 5 (tested them on the same device running iOS 8.1). – Mongrel Jedi Nov 17 '14 at 03:34
0

I tried several solutions, eventually the one that worked for me was.

I had to go into my plist, change

View controller-based status bar appearance = YES

And then controll the status bar in my view controllers by overriding the method prefersStatusBarHidden in each,

-(BOOL)prefersStatusBarHidden{
    return YES;
}
Krtko
  • 1,055
  • 18
  • 24
  • Thank you, actually I've tried that, but it doesn't resolve the issue that the status bar is displayed when a cordova plugin i.e. Photo selection is being run. I wonder if it involves updating the plugin's own source code to cater to the iOS 8 status bar settings. – Mongrel Jedi Apr 12 '15 at 15:59
  • Oh whilst the overlay is up. I did a quickie Google because I was curious and found this, http://stackoverflow.com/questions/18880364/uiimagepickercontroller-breaks-status-bar-appearance – Krtko Apr 13 '15 at 00:25
  • Thanks for the resource! I guess to fix such plugin issues, we'd either have to edit its source and recompile, or wait till the plugin is updated with the corresponding patch. – Mongrel Jedi Apr 13 '15 at 05:49