简体   繁体   English

如何开发针对iPad迷你与科尔多瓦/ PhoneGap的?

[英]How do I develop for the iPad mini with Cordova/Phonegap?

I want to develop for the iPad Mini, but the simulator doesn't come with the Xcode 4.5. 我想为iPad Mini进行开发,但是该模拟器不随Xcode 4.5一起提供。 Is there any way I can see what my app is going to look like on the new iPad Mini? 有什么办法可以让我在新的iPad Mini上看到我的应用程序的外观? I am using the Cordova framework. 我正在使用Cordova框架。

There is a simulator - it's called the iPad simulator. 有一个模拟器-它称为iPad模拟器。 The iPad mini has the same resolution as the iPad. iPad mini具有与iPad相同的分辨率。 The only difference is the pixel density - ie the iPad mini has a greater pixel density than the iPad. 唯一的区别是像素密度-即iPad mini的像素密度大于iPad。

Go to your AppDelegate.m file and replace it with the code here: 转到您的AppDelegate.m文件,并将其替换为以下代码:

    /*
 Licensed to the Apache Software Foundation (ASF) under one
 or more contributor license agreements.  See the NOTICE file
 distributed with this work for additional information
 regarding copyright ownership.  The ASF licenses this file
 to you under the Apache License, Version 2.0 (the
 "License"); you may not use this file except in compliance
 with the License.  You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing,
 software distributed under the License is distributed on an
 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 KIND, either express or implied.  See the License for the
 specific language governing permissions and limitations
 under the License.
 */

//
//  AppDelegate.m
//  YOUR PROJECT NAME HERE
//
//  Created by YOUR NAME HERE
//  Copyright YOUR NAME HERE 2012. All rights reserved.
//

#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(@"YOUR PROJECT NAME HERE 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];
    }

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

    CGFloat scale = 4.71f/5.82f;
    CGAffineTransform scaleTransform = CGAffineTransformMakeScale(scale, scale);
    self.window.transform = CGAffineTransformConcat(scaleTransform, self.window.transform);
    self.window.clipsToBounds = YES;

    [self statusBarChanged:nil];

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(statusBarChanged:)
                                                 name:UIApplicationDidChangeStatusBarOrientationNotification
                                               object:nil];

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardWillShow:)
                                                 name:UIKeyboardWillShowNotification
                                               object:nil];
    return YES;
}

- (void)statusBarChanged:(NSNotification *)note {
    CGFloat scale = 4.71f/5.82f;
    CGAffineTransform scaleTransform = CGAffineTransformMakeScale(scale, scale);
    UIWindow *statusBarWindow = (UIWindow *)[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"];
    statusBarWindow.transform = CGAffineTransformConcat(scaleTransform, statusBarWindow.transform);
}

- (void)keyboardWillShow:(NSNotification *)note {
    [self performSelector:(@selector(doMagicToKeyboard)) withObject:nil afterDelay:0];
}

-(void)doMagicToKeyboard {
    for (UIWindow *window in [[UIApplication sharedApplication] windows]) {
        [self checkForKeyboard:window];
    }
}

- (void)checkForKeyboard:(UIView *)view {
    static BOOL didIt = NO;
    for (UIView *currentView in view.subviews) {
        if(([[currentView description] hasPrefix:@"<UIKeyboard"] == YES) && !didIt)
        {
            didIt = YES;
            UIView *thisView = currentView.superview.superview;
            thisView.clipsToBounds = YES;
            CGFloat scale = 4.71f/5.82f;
            CGAffineTransform scaleTransform = CGAffineTransformMakeScale(scale, scale);
            thisView.transform = CGAffineTransformConcat(scaleTransform, thisView.transform);
        } else {
            [self checkForKeyboard:currentView];
        }
    }
}


// this happens while we are running ( in the background, or from within our own app )
// only valid if Ipad Mini-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];
}

@end

This will help people who want to develop for the iPad Mini; 这将为想要为iPad Mini开发的人们提供帮助。 giving them a chance to see exactly what their app will look like on the new iPad Mini. 让他们有机会确切了解他们的应用在新iPad Mini上的外观。 This would not be possible without the great article I read on Michael Slaters blog. 没有我在Michael Slaters博客上阅读的精彩文章,这是不可能的。 Here's the post where he walked me through the process of doing this for Cordova applications. 这是他指导我完成Cordova应用程序的整个过程。 Thanks Michael! 谢谢迈克尔!

http://blog.michaelslater.net/making-your-ipad-app-mini.html?fb_comment_id=fbc_396351297103051_3342141_397114960360018#f35ee51728 http://blog.michaelslater.net/making-your-ipad-app-mini.html?fb_comment_id=fbc_396351297103051_3342141_397114960360018#f35ee51728

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM