ConnectionRequest在iOS中不起作用

时间:2017-09-28 13:24:13

标签: codenameone

我已经一年了一个半旧的应用程序来更新。它是在statemachine中写的。现在我添加了一些东西,但是connectionRequest似乎在iOS中没有用(它是为iOS调试而构建的)。我在android中构建它并且它工作得非常好。

 public void connectionForLogin(String username, String password) {
    ConnectionRequest cr = new ConnectionRequest() {

        @Override
        protected void readResponse(InputStream input) throws IOException {
            JSONParser jSONParser = new JSONParser();
            Map<String, Object> parsedData = jSONParser.parseJSON(new InputStreamReader(input));
            ArrayList<Map<String, Object>> response = (ArrayList<Map<String, Object>>) parsedData.get("root");
            if (response != null) {
                for (Map<String, Object> element : response) {
                    success = (String) element.get("login");
                    msg = (String) element.get("msg");

                    ArrayList<Map<String, Object>> userInfoArray = (ArrayList) element.get("user_info");
                    Storage.getInstance().writeObject("userInfo", userInfoArray);
                }
            }
        }

        @Override
        protected void postResponse() {
            super.postResponse(); 
        }

        @Override
        protected void handleErrorResponseCode(int code, String message) {
        }

        @Override
        protected void handleException(Exception err) {
        }

        @Override
        protected void handleIOException(IOException err) {
        }

        @Override
        protected void handleRuntimeException(RuntimeException err) {
        }
    };
    cr.setPost(true);
    cr.setDuplicateSupported(true);
    cr.setTimeout(30000);
    AllUrl au = new AllUrl();
    InfiniteProgress ip = new InfiniteProgress();
    Dialog d = ip.showInifiniteBlocking();
    cr.setDisposeOnCompletion(d);
    cr.setUrl(http://zzz.com/api/logins/match? + "username=" + username + "&password=" + password);
    NetworkManager.getInstance().addToQueueAndWait(cr);
 }

1 个答案:

答案 0 :(得分:1)

这可能是由于新的Apple规定导致应用无法从非安全网址http获取数据。您可以通过添加以下构建提示暂时解决此问题:

ios.plistInject=<key>NSAppTransportSecurity</key><dict><key>NSAllowsArbitraryLoads</key><true/></dict><key>CFBundleURLTypes</key><array><dict><key>CFBundleURLName</key><string>com.mycompany.myapp</string></dict><dict><key>CFBundleURLSchemes</key><array><string>MyApp</string></array></dict></array> 

请注意,如果连接到不安全的网址,您的应用可能会被拒绝。