Skip to content

Instantly share code, notes, and snippets.

@nicoverbruggen
Last active August 29, 2015 13:57
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicoverbruggen/9492749 to your computer and use it in GitHub Desktop.
Save nicoverbruggen/9492749 to your computer and use it in GitHub Desktop.
Cordova iOS 7.0/7.1 optimizations. Also fixes for 7.1 arm64 crashes in plugins in CordovaLib < 3.5. Also includes fix for no splash screen on iPhone with 3.5" screen.

How to introduce arm64 support in Xcode 5.1

  1. Select your Project icon
  2. Choose Build Settings.
  3. For "Architectures", select $ARCHS_STANDARD - Standard architectures (armv7, armv7s, arm64)
  4. For "Valid Architectures", add "arm64"
  5. Select your CordovaLib.xcodeproj icon
  6. In the Build Settings for the Project (not Target), delete the conditional architecture settings (hover to see the minus sign)
  7. For "Architectures", select $ARCHS_STANDARD - Standard architectures (armv7, armv7s, arm64)
  8. For "Valid Architectures", add "arm64"
  9. Goto 6, but now do it for "Target"
// Fix for BAD_ACCESS on arm64 devices
// Per this diff: https://git-wip-us.apache.org/repos/asf?p=cordova-ios.git;a=blobdiff;f=CordovaLib/Classes/CDVCommandQueue.m;h=1eddfe37ee699289701cd4caaf68486607010501;hp=902dfa0227f1358296d2218fa0e6d5cc2a882ea6;hb=82ce4f2;hpb=7da5f2df3417de68a1b540bc00c11a95ce3dc7d6
// Should be fixed in CordovaLib 3.5
SEL normalSelector = NSSelectorFromString(methodName);
if ([obj respondsToSelector:normalSelector]) {
// [obj performSelector:normalSelector withObject:command];
((void (*)(id, SEL, id))objc_msgSend)(obj, normalSelector, command); // replace the old line with this one
} else {
// There's no method to call, so throw an error.
NSLog(@"ERROR: Method '%@' not defined in Plugin '%@'", methodName, command.className);
// Fix for BAD_ACCESS on arm64 devices
// Per this diff: https://git-wip-us.apache.org/repos/asf?p=cordova-ios.git;a=blobdiff;f=CordovaLib/Classes/CDVViewController.m;h=7bda2cc4a70dad895f452b02fde673b1884ed7d3;hp=10cfc4474a7025c335c431088d592e2ad1042d13;hb=82ce4f2;hpb=7da5f2df3417de68a1b540bc00c11a95ce3dc7d6
// Should be fixed in CordovaLib 3.5
CDVPlugin* plugin = [pluginObjects objectForKey:pluginName];
SEL selector = NSSelectorFromString(@"shouldOverrideLoadWithRequest:navigationType:");
if ([plugin respondsToSelector:selector]) {
if (((BOOL (*)(id, SEL, id, int))objc_msgSend)(plugin, selector, request, navigationType) == YES) { // replace the old line with this one
return NO;
}
}
// Custom color implementation
// Add the following to the file
#import "MainViewController.h"
@implementation UIColor (CustomColor)
+ (UIColor*)customColor {
return [UIColor colorWithRed:51.0/255.0 green:51.0/255.0 blue:51.0/255.0 alpha:1];
}
// In viewDidLoad, add the following:
- (void)viewDidLoad
{
[super viewDidLoad];
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
CGRect viewBounds = [self.webView bounds];
viewBounds.origin.y = 20;
viewBounds.size.height = viewBounds.size.height - 20;
self.webView.frame = viewBounds;
}
// CUSTOM COLOR HERE!
self.view.backgroundColor = [UIColor customColor];
}
@end
<!-- Add the following preference to the widget element
This disallows rubber banding for the entire WebView
(but this disables rubber banding of overflowing content,
which is fixed in fixes.js + css file) -->
<widget id="myapp" ...>
<preference name="DisallowOverscroll" value="true" />
</widget>
// I use a Foundation offpage sidebar, but it should always be 100% height
// no matter how heigh the main content is.
var timer;
$(window).resize(function() {
clearTimeout(timer);
// Timer that adjusts 'window' and view to fit proper sizes
// depending on device. This ensures that scrolling works nice!
timer = setTimeout(function() {
// Minimal height for sidebar
$('.inner-wrap').css("min-height", $(window).height() + "px" );
// Maximal height set to device height for view, but should be scrollable
// Same for off-canvas menu and body
$('#view').css("max-height", ($(window).height()-45) + "px" );
$('.left-off-canvas-menu').css("max-height", ($(window).height()) + "px" );
$('body').css("max-height", $(window).height() + "px" );
}, 40);
}).resize();
body{
// Default font for Android is Roboto
// Fallback font for iOS is Helvetica Neue, otherwise sans
font-family: "Helvetica Neue", "Roboto", sans-serif !important;
// Hide overflow to ensure top menu remains at the top
// Note that overflow needs to be manually fixed
overflow: hidden;
}
.left-off-canvas-menu{
overflow: scroll; // Let overflow of the offscreen menu be scrollable
-webkit-touch-callout:none !important; // Disallow hold tapping on links in sidebar
-webkit-overflow-scrolling: touch; // Allow for rubber banding
}
#view{
overflow: auto; // Again, allow for overflow scrolling
-webkit-overflow-scrolling: touch; // And allow for rubber banding
}
@interface UIColor (CustomColor)
+ (UIColor*)customUIColor; // Custom UI color for better integration with your app's style
@end
// Fixes for iOS 7 status bar (transparent & overlaps with your webview)
- (void)viewDidLoad
{
[super viewDidLoad];
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
CGRect viewBounds = [self.webView bounds];
viewBounds.origin.y = 20;
viewBounds.size.height = viewBounds.size.height - 20;
self.webView.frame = viewBounds;
}
self.view.backgroundColor = [UIColor blackColor];
}

Guide to getting Network Connection plugin installed

If you get the following error:

Installing org.apache.cordova.network-information (ios) Error during processing of action! Attempting to revert...

You have to manually install the plugin.

This means adjusting iOS.json and downloading the sources into your Xcode project under Cordova's /Plugins dir.

Also, you need to go to your project, Build Phases and add SystemConfiguration.framework as a required link with libraries.

Splash screen fix for 3.5" iPhone (Cordova 3.4)

It seems to be some kind of bug in CDVSplashScreen. Notice how it says in the Output that it couldn't find the image "Default-Portrait". (It should be looking for another file, "Default", not "Default-Portrait".)

WARNING: The splashscreen image named Default-Portrait was not found

What I did was the following:

  • Create a new splash screen named Default-Portrait@2x~iphone.png (a copy of Default@2x~iphone.png) and add it to the splash directory under Resources. (If you need to support iOS 6 you'll probably need a Default-Portrait~iphone.png file as well.) Don't just rename the file, or Xcode might not build your project due to a missing file.

  • Ensure that you also make sure that this new file is in your project list. (I didn't rebuild the project with cordova build ios so I had to drag the file from finder to the project files in Xcode. Not sure if rebuilding automatically adds it to your Xcode project.)

This should solve your problem.

I just switched to Xcode 5.1 and iOS 7.1 and Cordova has some issues with the new SDK as well. If you stumble upon some issues with Xcode 5.1 & iOS 7.1, I would also like to link you to the following page.

@nicoverbruggen
Copy link
Author

Added:

  • Instructions to fix BAD_ACCESS errors in live arm64 devices for plugins (doesn't crash in simulator)
  • Instructions to get 7.1 projects to build for arm64 devices

@nicoverbruggen
Copy link
Author

Added:

  • Instructions to add Network Plugin.
  • Instructions for custom status bar color implementation.

@tshong
Copy link

tshong commented May 5, 2014

you saved me lots of time !!
thanks you so much !!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment