How to set up UIWebView retention listing in place

I was wondering how I can override the UIActionSheet that appears when I click and hold on the link in the UIWebView (it shows the link and the open and copy buttons). I need to add a button to the alert, but I don’t know how to configure it.

Does anyone have an idea on how to solve this?

+3
source share
1 answer

Given that there is no such API, you can still customize the non-standard-api-like-way worksheet without using a private api. The easiest way is probably to watch the views of this web view, and when one appears (for example, a pop-up window), it checks its class and, if it is such a pop-up window, it can be configured. This is how I try it.

However: this is hacky and could easily break in the next update.

Add observation:

[myWebView addObserver:self forKeyPath:@"subviews" options:0 context:@"popup"];

Then observe:

- (void)observeValueForKeyPath:(NSString *)keyPath
                      ofObject:(id)object
                        change:(NSDictionary *)change
                       context:(void *)context
{
    if (context == @"popup") {
        for (UIView *view in [object subviews]) {
            if ([view isKindOfClass: [UIAlertView class]])
                 [self customizeAlert: (UIAlertView*)view];
        }
    }
    [super observeValueForKeyPath:keyPath
                         ofObject:object
                           change:change
                          context:context];
}

Then do your setup in this way:

- (void)customizeAlert:(UIAlertView*)alert { ... }
+3
source

Source: https://habr.com/ru/post/1762733/


All Articles