ios报错
在AppDelegate.m文件在最后加入(在@end后面加空行): @implementation NSURLRequest(DataController) + (BOOL)allowsAnyHTTPSCertificateForHost:(NSString *)host { return YES; } @end
android没出错,出错可以这么解决
main.java,友盟继承的可以不用看: [java] view plaincopy在CODE上查看代码片派生到我的代码片 public class main extends CordovaActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); UmengUpdateAgent.setUpdateOnlyWifi(false); UmengUpdateAgent.update(this); super.init(); // Set by <content src="index.html" /> in config.xml super.loadUrl(Config.getStartUrl()); //super.loadUrl("file:///android_asset/www/index.html") } @Override protected CordovaWebViewClient makeWebViewClient(CordovaWebView webView) { // TODO Auto-generated method stub if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) { return new SSLAcceptingCordovaWebViewClient(this, webView); } else { return new SSLAcceptingIceCreamCordovaWebViewClient(this, webView); } } } SSLAcceptingCordovaWebViewClient: [java] view plaincopy在CODE上查看代码片派生到我的代码片 import org.apache.cordova.CordovaInterface; import org.apache.cordova.CordovaWebView; import org.apache.cordova.CordovaWebViewClient; import org.apache.cordova.DroidGap; import android.net.http.SslError; import android.webkit.SslErrorHandler; import android.webkit.WebView; public class SSLAcceptingCordovaWebViewClient extends CordovaWebViewClient{ public SSLAcceptingCordovaWebViewClient(CordovaInterface cordova, CordovaWebView view) { super(cordova, view); // TODO Auto-generated constructor stub } @Override public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) { // testing against getPrimaryError() or hasErrors() will fail on Honeycomb or older. // You might check for something different, such as specific info in the certificate, //if (error.getPrimaryError() == SslError.SSL_IDMISMATCH) { handler.proceed(); //} else { // super.onReceivedSslError(view, handler, error); //} } } SSLAcceptingIceCreamCordovaWebViewClient.java,名字有点长,网上参考下来的,也懒得去改了: [java] view plaincopy在CODE上查看代码片派生到我的代码片 import org.apache.cordova.CordovaInterface; import org.apache.cordova.CordovaWebView; import org.apache.cordova.IceCreamCordovaWebViewClient; import android.net.http.SslError; import android.webkit.SslErrorHandler; import android.webkit.WebView; public class SSLAcceptingIceCreamCordovaWebViewClient extends IceCreamCordovaWebViewClient { public SSLAcceptingIceCreamCordovaWebViewClient(CordovaInterface cordova, CordovaWebView view) { super(cordova, view); } @Override public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) { handler.proceed(); } }