Remove form assistant from keyboard in iPhone standalone web app

后端 未结 3 2024
無奈伤痛
無奈伤痛 2020-12-05 05:16

Is it possible to remove the form assistant from the iPhone popup keyboard in a standalone web app? I know the general consensus is that it\'s not possible in Mobile Safari,

相关标签:
3条回答
  • 2020-12-05 06:05

    If you app is a web app wrapped in a native Objetive-C app this is possible by manipulating Keyboard views.

    first, register to receive the keyboardDidShow notification:

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidShow:) name:UIKeyboardDidShowNotification object:nil];
    

    this will call the following method when keyboard shows up:

    -(void)keyboardDidShow:(NSNotification*)notif
    {
        NSArray *array = [[UIApplication sharedApplication] windows];
    
        for (UIWindow* wind in array) {
            for (UIView* currView in wind.subviews) {
                if ([[currView description] hasPrefix:@"<UIPeripheralHostView"]) {
                    for (UIView* perView in currView.subviews) {
                        if ([[perView description] hasPrefix:@"<UIWebFormAccessory"]) {
                            [perView setHidden:YES];
                        }
                    }
    
                }
            }
        }
    }
    

    this method goes over the views on screen looking for the form assistant and hiding it.

    NOTE: Apple probably won't reject this, as i've seen it being used by Facebook etc, but this technique might break in upcoming iOS releases.

    0 讨论(0)
  • 2020-12-05 06:08

    All signs point to this not being possible, including several questions here.

    0 讨论(0)
  • 2020-12-05 06:21

    You can do a category of UIView and "override" the behaviour of addSubview: like the example below. Call the method "exachangeMethods" from your applicationDidFinishLaunching of your AppDelegate.

    #import "UIView+util.h"
    #import <objc/runtime.h>
    
    @implementation UIView (util)
    
    // Swaps our custom implementation with the default one
    // +load is called when a class is loaded into the system
    + (void) exchangeMethods
    {
        SEL origSel = @selector(addSubview:);
    
        SEL newSel = @selector(customAddSubview:);
    
        Class viewClass = [UIView class];
    
        Method origMethod = class_getInstanceMethod(viewClass, origSel);
        Method newMethod = class_getInstanceMethod(viewClass, newSel);
        method_exchangeImplementations(origMethod, newMethod);
    }
    - (void) customAddSubview:(UIView *)view{
    
        if( [[view description]rangeOfString:@"<UIWebFormAccessory"].location!=NSNotFound) {
            return;
        }
    
        // This line at runtime does not go into an infinite loop
        // because it will call the real method instead of ours.
        return [self customAddSubview:view];
    
    }
    
    @end
    
    0 讨论(0)
提交回复
热议问题