web view can't load web page

web view can't load web page

Hello, I add webview control through code, , but no page is loaded.

Thanks!

The following is the code.

   @Override
    public void viewDidLoad() {
        super.viewDidLoad();
//        statusText = getLabel();
//        helloButton = getHelloButton();

        myWebView = UIWebView.alloc().initWithFrame(this.view().frame());
        this.view().addSubview(myWebView);
        myWebView.loadRequest(NSURLRequest.requestWithURL(NSURL.URLWithString("http://www.baidu.com")));
    }
9 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

The error message:

App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file.

 

but there is no Info.plist file, even open Xcode,

if I use https protocol, the error message  is :
   NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9802)
if I use http protocol, the error message is:
     App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file.



 @Override
    public void viewDidLoad() {
        super.viewDidLoad();
//        statusText = getLabel();
//        helloButton = getHelloButton();

        myWebView = UIWebView.alloc().initWithFrame(this.view().frame());
        this.view().addSubview(myWebView);
        myWebView.loadRequest(NSURLRequest.requestWithURL(NSURL.URLWithString("https://www.baidu.com")));
    }

Dear Rad,

If you don't have a custom Info.plist file, then please copy the one generated during build (build/xcode/<project>/Info.plist) and copy it into src/main/resources/Info.plist. Then you need to edit the build.gradle file and add xcode.infoPlistPath 'src/main/resources/Info.plist' into the moe { ... } scope.

Now you can add the required values to the Info.plist file. I attached a screenshot what the keys and values should look like.

Best Regards,
Kristóf

Attachments: 

AttachmentSize
Downloadimage/png AppTransSec.png12.27 KB

 

 

 

Dear Kristof Liliom,

       Two question,  my Xcode version is 7.3.1, moe is 1.0.702, android is api level 19, idk is idk 8, android studio is 2.1.2

       1. I do it according your suggestion, another error message:

2016-08-06 08:33:04.867 web[2244:42281] NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9802)
Child process terminated with signal 9: Killed 

       2. From the web, I know Apple require using https from year 2017, So I use https, but the error message is :

2016-08-06 08:33:04.867 web[2244:42281] NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9802)

      3. the complete source code:

package com.web.web.ui;

import com.intel.moe.natj.general.Pointer;
import com.intel.moe.natj.general.ann.Owned;
import com.intel.moe.natj.general.ann.RegisterOnStartup;
import com.intel.moe.natj.objc.ObjCRuntime;
import com.intel.moe.natj.objc.ann.ObjCClassName;
import com.intel.moe.natj.objc.ann.Property;
import com.intel.moe.natj.objc.ann.Selector;

import ios.NSObject;
import ios.foundation.NSURL;
import ios.foundation.NSURLRequest;
import ios.uikit.UIButton;
import ios.uikit.UILabel;
import ios.uikit.UIViewController;
import ios.uikit.UIWebView;

@com.intel.moe.natj.general.ann.Runtime(ObjCRuntime.class)
@ObjCClassName("AppViewController")
@RegisterOnStartup
public class AppViewController extends UIViewController {

    @Owned
    @Selector("alloc")
    public static native AppViewController alloc();

    @Selector("init")
    public native AppViewController init();

    protected AppViewController(Pointer peer) {
        super(peer);
    }

    private UIWebView myWebView = null;

    @Override
    public void viewDidLoad() {
        super.viewDidLoad();
//        statusText = getLabel();
//        helloButton = getHelloButton();

        myWebView = UIWebView.alloc().initWithFrame(this.view().frame());
        this.view().addSubview(myWebView);
        myWebView.loadRequest(NSURLRequest.requestWithURL(NSURL.URLWithString("http://www.baidu.com")));
    }


}

Thank you very much! 

 

Dear Rad,

The screenshot I made was what it should look like from within Xcode. The raw key/value pairs are:

    <key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
    </dict>

This should only fix the http requests.

The other issue (NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9802)) as far as I know comes from iOS not accepting the server's security settings. iOS 9 apps require servers to have TLSv1.2, but I'm not sure of this.

Best Regards,
Kristóf

Dear Kristof Liliom,

      Thanks for your reply.

      Could you give a very simple example that can run http, https for me? Maybe I have missing some information.

      Thank you very much!

Best Regards

Rad

Dear Rad,

I attached a simple example.
- This sample loads HTTP and HTTPS sites, you can switch between them by clicking on the button at the top of the app's window
- URL load implementation is in: src/main/java/com/example/simplehttp/ui/AppViewController.java
- Custom Info.plist is here: src/main/resources/Info.plist
- Added this line to build.gradle: xcode.infoPlistPath 'src/main/resources/Info.plist'

Best Regards,
Kristóf

Attachments: 

AttachmentSize
Downloadapplication/zip SimpleHTTP.zip83.12 KB

Dear Kristof Liliom,

      - Added this line to build.gradle: xcode.infoPlistPath 'src/main/resources/Info.plist'

       Yes, I missed the step.

       Another issue, I run your example, the http protocol is ok, when I switch to https, the error message is:

2016-08-08 07:41:21.799 SimpleHTTP[1230:18078] NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9813)

     Thanks!

Best Regards,

Rad

      

Leave a Comment

Please sign in to add a comment. Not a member? Join today