Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Phonegap iOS6: Proper solution to Remove form assistant bar (prev, next, done)

Another "how to remove the pre, next, done button" -question you may think. Not really actually. I've done some rather thorough research on this and tried out different approaches but no method or solution really seems to do it right. All workaround (that's what they are) mentioned and shown below are basically the same approach, replace content of the MainViewController.m file. I'm well aware of that more or less all these proposed solutions are somewhat hacky but still, there should be someone out there who has tackled this issue with a little bit of grace and deep thought, or someone who knows C well and can propose a more solid solution.

Allow me to illustrate my point by making references to some proposed solutions:

Solution 1

In iOS6, this results in the form assistant bar border still being present and the keyboard acting as if the form assistant bar were still there.

Solution 2

Someone proposed a solution to the above but I simply cannot get it to work. The answerer has made several edits and comments to the post which only make harder to grasp what to do where. I've tried all variations of his solution but I always end up getting a critical error and the project simply wont compile.

Solution 3

Not a C programmer (that's why I use phonegap) so can't get this to work properly. Don't know what to add where.

Solution 4

Don't know where and how to implement this so haven't tried it. Where should I register to receive the keyboardDidShow notification? Where should I add the function?

Conclusion

According to my research, if you will, no one has yet proposed a proper solution to this. So has anyone successfully removed the form assistant without any of the above mentioned side effects?

like image 286
Lindros Avatar asked Dec 13 '12 00:12

Lindros


2 Answers

Here you go, I'm using this in an app I'm currently developing. Fingers crossed that it gets to the app store, although going on other 'hacks' that make it to the store this is no worse than others, so should stand a fair chance.

No annoying side effects with this method - it cleanly removes the bar by making sure it's never created in the first place. Ta da!

Credit goes to https://gist.github.com/2048571, this is his code with a small fix.

#import <objc/runtime.h>
#import <UIKit/UIKit.h>

@interface UIWebView (HackishAccessoryHiding)
@property (nonatomic, assign) BOOL hackishlyHidesInputAccessoryView;
@end

@implementation UIWebView (HackishAccessoryHiding)

static const char * const hackishFixClassName = "UIWebBrowserViewMinusAccessoryView";
static Class hackishFixClass = Nil;

- (UIView *)hackishlyFoundBrowserView {
    UIScrollView *scrollView = self.scrollView;

    UIView *browserView = nil;
    for (UIView *subview in scrollView.subviews) {
        if ([NSStringFromClass([subview class]) hasPrefix:@"UIWebBrowserView"]) {
            browserView = subview;
            break;
        }
    }
    return browserView;
}

- (id)methodReturningNil {
    return nil;
}

- (void)ensureHackishSubclassExistsOfBrowserViewClass:(Class)browserViewClass {
    if (!hackishFixClass) {
        Class newClass = objc_allocateClassPair(browserViewClass, hackishFixClassName, 0);
        IMP nilImp = [self methodForSelector:@selector(methodReturningNil)];
        class_addMethod(newClass, @selector(inputAccessoryView), nilImp, "@@:");
        objc_registerClassPair(newClass);

        hackishFixClass = newClass;
    }
}

- (BOOL) hackishlyHidesInputAccessoryView {
    UIView *browserView = [self hackishlyFoundBrowserView];
    return [browserView class] == hackishFixClass;
}

- (void) setHackishlyHidesInputAccessoryView:(BOOL)value {
    UIView *browserView = [self hackishlyFoundBrowserView];
    if (browserView == nil) {
        return;
    }
    [self ensureHackishSubclassExistsOfBrowserViewClass:[browserView class]];

    if (value) {
        object_setClass(browserView, hackishFixClass);
    }
    else {
        Class normalClass = objc_getClass("UIWebBrowserView");
        object_setClass(browserView, normalClass);
    }
    [browserView reloadInputViews];
}

@end
like image 79
Jordan Smith Avatar answered Nov 12 '22 23:11

Jordan Smith


For anyone still struggling with this, Phonegap now has two properties for disabling the form accessory bar issue and the problem of page scrolling when input and text area fields trigger the keyboard.

Just set the following in your config.xml and your good to go.

<preference name="HideKeyboardFormAccessoryBar" value="true" />
<preference name="KeyboardShrinksView" value="true" />

Link to Phonegap Documentation

like image 7
PassKit Avatar answered Nov 13 '22 00:11

PassKit