Created
August 14, 2012 09:09
-
-
Save lbj96347/3347717 to your computer and use it in GitHub Desktop.
Phonegap_AppDelegate_Config
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| 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 | |
| // test | |
| // | |
| // Created by CashLee on 12-5-8. | |
| // Copyright __MyCompanyName__ 2012年. All rights reserved. | |
| // 文件中配置了Push Notification以及键盘优化的代码(如果你不需要Push Notification功能,请自行将代码删除 | |
| #import "AppDelegate.h" | |
| #import "MainViewController.h" | |
| //添加了PushNotification文件进来 | |
| #import "PushNotification.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 ,invokeString; | |
| - (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) | |
| * 应用主要的View还有功能设置都在这里进行setup | |
| */ | |
| - (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(@"test 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]; | |
| /* START BLOCK */ | |
| // PushNotification - Handle launch from a push notification | |
| NSDictionary* userInfo = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]; | |
| if(userInfo) { | |
| PushNotification *pushHandler = [self.viewController getCommandInstance:@"PushNotification"]; | |
| NSMutableDictionary* mutableUserInfo = [userInfo mutableCopy]; | |
| [mutableUserInfo setValue:@"1" forKey:@"applicationLaunchNotification"]; | |
| [mutableUserInfo setValue:@"0" forKey:@"applicationStateActive"]; | |
| [pushHandler.pendingNotifications addObject:mutableUserInfo]; | |
| } | |
| /* STOP BLOCK */ | |
| /* deal with keyboard */ | |
| /* 处理键盘view,调用一段待会要引入的函数 */ | |
| [[NSNotificationCenter defaultCenter] | |
| addObserver:self | |
| selector:@selector(keyboardWillShow:) | |
| name:UIKeyboardWillShowNotification | |
| object:nil]; | |
| return YES; | |
| } | |
| // this happens while we are running ( in the background, or from within our own app ) | |
| // only valid if test-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]; | |
| } | |
| /* edit appDelegate file */ | |
| /* START BLOCK */ | |
| #pragma PushNotification delegation | |
| - (void)application:(UIApplication*)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken | |
| { | |
| PushNotification* pushHandler = [self.viewController getCommandInstance:@"PushNotification"]; | |
| [pushHandler didRegisterForRemoteNotificationsWithDeviceToken:deviceToken]; | |
| } | |
| - (void)application:(UIApplication*)app didFailToRegisterForRemoteNotificationsWithError:(NSError*)error | |
| { | |
| PushNotification* pushHandler = [self.viewController getCommandInstance:@"PushNotification"]; | |
| [pushHandler didFailToRegisterForRemoteNotificationsWithError:error]; | |
| } | |
| - (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo | |
| { | |
| PushNotification* pushHandler = [self.viewController getCommandInstance:@"PushNotification"]; | |
| NSMutableDictionary* mutableUserInfo = [userInfo mutableCopy]; | |
| // Get application state for iOS4.x+ devices, otherwise assume active | |
| UIApplicationState appState = UIApplicationStateActive; | |
| if ([application respondsToSelector:@selector(applicationState)]) { | |
| appState = application.applicationState; | |
| } | |
| [mutableUserInfo setValue:@"0" forKey:@"applicationLaunchNotification"]; | |
| if (appState == UIApplicationStateActive) { | |
| [mutableUserInfo setValue:@"1" forKey:@"applicationStateActive"]; | |
| [pushHandler didReceiveRemoteNotification:mutableUserInfo]; | |
| } else { | |
| [mutableUserInfo setValue:@"0" forKey:@"applicationStateActive"]; | |
| [mutableUserInfo setValue:[NSNumber numberWithDouble: [[NSDate date] timeIntervalSince1970]] forKey:@"timestamp"]; | |
| [pushHandler.pendingNotifications addObject:mutableUserInfo]; | |
| } | |
| } | |
| /* STOP BLOCK */ | |
| /** | |
| Called when the webview finishes loading. This stops the activity view and closes the imageview | |
| */ | |
| // hiding UIWebviewAccessary | |
| // 隐藏键盘的Assistant bar 函数加入在这个地方 | |
| - (void)keyboardWillShow:(NSNotification *)note { | |
| [self performSelector:@selector(removeBar) withObject:nil afterDelay:0]; | |
| } | |
| - (void)removeBar { | |
| // Locate non-UIWindow. | |
| UIWindow *keyboardWindow = nil; | |
| for (UIWindow *testWindow in [[UIApplication sharedApplication] windows]) { | |
| if (![[testWindow class] isEqual:[UIWindow class]]) { | |
| keyboardWindow = testWindow; | |
| break; | |
| } | |
| } | |
| // Locate UIWebFormView. | |
| for (UIView *possibleFormView in [keyboardWindow subviews]) { | |
| // iOS 5 sticks the UIWebFormView inside a UIPeripheralHostView. | |
| if ([[possibleFormView description] rangeOfString:@"UIPeripheralHostView"].location != NSNotFound) { | |
| for (UIView *subviewWhichIsPossibleFormView in [possibleFormView subviews]) { | |
| if ([[subviewWhichIsPossibleFormView description] rangeOfString:@"UIWebFormAccessory"].location != NSNotFound) { | |
| [subviewWhichIsPossibleFormView removeFromSuperview]; | |
| } | |
| } | |
| } | |
| } | |
| } | |
| /* 以上这一部分就是隐藏键盘assistant bar 代码了 :-) */ | |
| @end |
Author
@chengrenz 对的,在beta版本已经测试过,这个问题的确存在,目前我也在想方设法找出那个问题所在。主要是希望找到那个View到底在哪,shadow到底从哪来,然后杀死。
额,ios8下还是存在
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
您好,您的代码确实可以隐藏 那一栏,不过,你在ios6上测试过吗,隐藏后,上面会多出一条黑线来,那条线没法隐藏,您能想办法处理下吗,谢谢。