Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I install this script into PhoneGap for iOS

I don't know any Objective-C, that is why I'm using PhoneGap to create an iOS app. There is a big flaw in PhoneGap for iOS. The keyboard constantly has the form assistant (the 'next', 'previous' and 'done' buttons.) There is very little information on the web on how to get rid of this, all of the Stackoverflow questions about it said it was practically impossible. But after a while I stumbled upon this tutorial. The bottom paragraph tells you how to do it. And it works, I downloaded and tested the finished app.

But since I have no idea how to do almost anything in Xcode, or in Objective-C, I have no idea what files the two sections of code go into, he doesn't say in the tutorial.

Can anyone tell me where in the PhoneGap apps files it goes? I'd appreciate it massively, this has been bugging me all day.

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

And this

RichTextEditorViewController *viewController = [[RichTextEditorViewController alloc] initWithNibName:@"RichTextEditorViewController" bundle:nil];
self.viewController = [[UINavigationController alloc] initWithRootViewController:viewController];

Also this

- (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];
                }
            }
        }
    }
}

Thank you!

like image 512
Joshua Davis Avatar asked Jan 03 '12 20:01

Joshua Davis


1 Answers

I have come across the need to do this myself. I am an IOS developer, but needed to use phonegap to keep costs down for multiplatform dev.

Anyway, i fixed your code. As, i guess, you dont want to spend your time learning obj-c, you just need to replace the contents of your MainViewController.m with the following:

#import "MainViewController.h"

@implementation MainViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return [super shouldAutorotateToInterfaceOrientation:interfaceOrientation];
}

- (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];
                }
            }
        }
    }
}

- (void)keyboardWillShow:(NSNotification*) notification {
    // remove the bar in the next runloop (not actually created at this point)
    [self performSelector:@selector(removeBar) withObject:nil afterDelay:0];
}

@end

As a word of warning, this is a bit of a hacky solution (but then so is using phonegap!), and may break in future versions of iOS. But i guess we fix that when it comes to it...

like image 174
Nick Hingston Avatar answered Sep 19 '22 10:09

Nick Hingston