Note that there are some explanatory texts on larger screens.

plurals
  1. POJavascript alert cause freeze. ( With AFNetworking and native code callback)
    primarykey
    data
    text
    <p>I want to do following list.</p> <ol> <li>use UIWebView</li> <li>Button on webview is tapped , then exec native code(http request) and get Response.</li> </ol> <p>I can get Response. But, It's not work 'alert' correctly in callback function(freeze).</p> <p>Why do like that?</p> <p>Thank you.</p> <h2>TextViewController</h2> <pre><code>#import "TestViewController.h" #import "AFNetworking.h" @interface TestViewController () @end @implementation TestViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization] [self initWebView] ; } return self; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (void)initWebView{ self.webView = [[UIWebView alloc] initWithFrame:SCREEN_APPLICATIONFRAME] ; [self.view addSubview:self.webView] ; self.webView.delegate = self ; [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"SOME_HTML"]]] ; } -(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *) request navigationType:(UIWebViewNavigationType)navigationType { if ([ request.URL.scheme isEqualToString:@"native" ]) { if ([request.URL.host isEqualToString:@"foo"]) { NSURL *url = [[NSURL alloc]initWithString:@"SOME_JSON_RESPONSE_URL"] ; NSURLRequest *request = [NSURLRequest requestWithURL:url]; AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) { NSLog(@"SUCCESS") ; [self.webView stringByEvaluatingJavaScriptFromString:@"cbFoo('OK')"] ; } failure:^(NSURLRequest *request, NSURLResponse *response, NSError *error, id JSON){ NSLog(@"ERROR: %@",error) ; [self.webView stringByEvaluatingJavaScriptFromString:@"cbFoo('NG')"] ; }]; [operation start] ; } return NO; } // 通常のschemeの場合は、フックせずそのまま処理を続ける else { return YES; } } @end </code></pre> <h2>SOME_HTML is like this.</h2> <pre><code>&lt;html&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset= UTF-8"&gt; &lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; // callback from native function cbFoo(result){ alert(result) ; // FREEZE!! alert('1st') ; alert('2nd') ; } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;a href="native://foo" &gt;Native Func&lt;/a&gt;&lt;br&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload