最近公司在開發(fā)web型的app楣嘁,涉及許多交互,剛好珍逸,我遇到j(luò)s中 的Alter/Confirm/Prompt三個彈框提示函數(shù)的坑逐虚,今天記錄解決的辦法下來,供大家使用谆膳。
1叭爱、在開發(fā)過程中,前端使用了他們自己的彈框框架漱病,結(jié)果在iOS和Android端展示這樣子买雾,多了http。
2杨帽、為了解決這樣的問題漓穿,百度了許多,最終借助百度上的資料和官方文檔注盈,試驗(yàn)成功了晃危。
3、其實(shí)不難解決這個問題老客,新建個UIWebView類別僚饭,在m文件寫上如下代碼,即可胧砰。
- (void)webView:(UIWebView *)sender runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(CGRect *)frame {
UIAlertView* customAlert = [[UIAlertView alloc] initWithTitle:@"溫馨提示" message:message delegate:nil cancelButtonTitle:@"確定" otherButtonTitles:nil];
[customAlert show];
}
static BOOL diagStat = NO;
static NSInteger bIdx = -1;
-
(BOOL)webView:(UIWebView *)sender runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(id)frame{
diagStat = NO;
bIdx = -1;
UIAlertView *confirmDiag = [[UIAlertView alloc] initWithTitle:@"溫馨提示"
message:message
delegate:self
cancelButtonTitle:@"取消"
otherButtonTitles:@"確定", nil];[confirmDiag show];
while (bIdx==-1) {
//[NSThread sleepForTimeInterval:0.2];
[[NSRunLoop mainRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.1f]];
}
if (bIdx == 0){//取消;
diagStat = NO;
}
else if (bIdx == 1) {//確定;
diagStat = YES;
}
return diagStat;
} (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
bIdx = buttonIndex;
}-
(NSString *) webView:(UIWebView *)view runJavaScriptTextInputPanelWithPrompt:(NSString *)prompt defaultText:(NSString *)text initiatedByFrame:(id)frame{
diagStat = NO;
bIdx = -1;
UIAlertView *confirmDiag = [[UIAlertView alloc] initWithTitle:@"溫馨提示" message:prompt
delegate:self
cancelButtonTitle:@"取消"
otherButtonTitles:@"確定", nil];
[confirmDiag setAlertViewStyle:UIAlertViewStylePlainTextInput];
UITextField *textField = [confirmDiag textFieldAtIndex:0];
textField.placeholder = @"請輸入信息";
textField.keyboardType = UIKeyboardTypeDefault;
[confirmDiag show];
while (bIdx==-1) {
//[NSThread sleepForTimeInterval:0.2];
[[NSRunLoop mainRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.1f]];
}
if (bIdx == 0){//取消;
diagStat = NO;
}
else if (bIdx == 1) {//確定;
diagStat = YES;
}
return textField.text;
效果如下:
}