When using Cordova for cross-platform development, the Uialertview title of the JS call confirm converted to iOS is displayed as a xxxx.html problem.
The first thing I think about is listening to uiapplication windows and then manually modifying the title of the current alert. Previously did a similar monitoring system notification, modify the style. However, it is much less efficient to interact with JS.
Another way of thinking is if it is better to find confirm into alert? This allows the method to be overloaded and replaced with any style.
On the StackOverflow really found, wow haha.
@interface UIWebView (Javascriptalert)
-(void) WebView: (uiwebview *) sender Runjavascriptalertpanelwithmessage: (nsstring *) Message initiatedbyframe: (ID) frame;
-(BOOL) WebView: (uiwebview *) sender Runjavascriptconfirmpanelwithmessage: (nsstring *) Message initiatedbyframe: (ID) frame;
-(nsstring *) WebView: (uiwebview *) View runjavascripttextinputpanelwithprompt: (nsstring *) Prompt DefaultText: (nsstring *) text initiatedbyframe: (ID) frame;
@end
Then I searched again on the csdn and found someone else's realization, and finally decided it was in this
-(BOOL) WebView: (uiwebview *) sender Runjavascriptconfirmpanelwithmessage: (nsstring *) Message initiatedbyframe: (ID) Frame {
The style of the alert is modified, and the method needs to return the index of the currently selected alert, which means that the current thread must be suspended before the alert is clicked. This is used to run the loop runloop.
The methods found on the Internet are basically outdated, and I have slightly modified the following:
#import "Uiwebview+javascriptalert.h"
@implementation UIWebView (Javascriptalert)
Static BOOL status = NO;
Static BOOL isend =NO;
-(void) WebView: (uiwebview *) sender Runjavascriptalertpanelwithmessage: (nsstring *) Message initiatedbyframe: (ID) Frame {
Uialertview* Customalert = [[uialertviewalloc] initwithtitle:Nil
message: Message
delegate:Nil
cancelbuttontitle:@ " OK "
otherbuttontitles:nil];
[Customalertshow];
}
-(nsstring *) WebView: (uiwebview *) View runjavascripttextinputpanelwithprompt: (nsstring *) Prompt DefaultText: (nsstring *) text initiatedbyframe: (ID) Frame {
return @"";
}
-(BOOL) WebView: (uiwebview *) sender Runjavascriptconfirmpanelwithmessage: (nsstring *) Message initiatedbyframe: (ID) Frame {
uialertview *confirmdiag = [[uialertviewalloc] initwithtitle:Nil
message: Message
delegate: Self
cancelbuttontitle:@ " cancel "
otherbuttontitles:@ " OK ",Nil];
[Confirmdiagshow];
cgfloat Version = [[[uidevicecurrentdevice] systemversion ]floatvalue];
if (Version >= 7.) {
while (isend = =NO) {
[ [nsrunloopmainrunloop] rununtildate: [nsdatedat Ewithtimeintervalsincenow:0.01f];
}
}Else
{
while (isend = =NO && confirmdiag. superview ! =Nil) {
[ [nsrunloopmainrunloop] rununtildate: [nsdatedat Ewithtimeintervalsincenow:0.01f];
}
}
isend = NO;
return status;
}
-(void) Alertview: (uialertview *) Alertview clickedbuttonatindex: (nsinteger) buttonindex {
status = Buttonindex;
isend = YES;
}
@end
Version compatible that piece did not test, because I only do iOS7, 8, no device test. Because it is a method of classifying overloads, dragging this category directly into the project does not require adding any code to achieve the desired effect.
Solve the title problem of JS confirm conversion to iOS Uialertview