2017-09-28 34 views
2

我已經有一年的時間&需要更新。它是用國家機器書寫的。現在我添加了一些東西,但connectionRequest在iOS中似乎不起作用(它是爲iOS調試而構建的)。我在android中構建它,它工作得很好。ConnectionRequest在iOS中無法正常工作

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); 
} 
+0

這是由於網址? API在http中,我認爲iOS需要https。但如果是這樣,爲什麼以前的版本工作正常? – beck

回答

1

這可能是由於新的蘋果法規阻止應用程序從非安全URL 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> 

注意,如果連接到非安全的網址你的應用程序可能會被拒絕。

+0

我在構建提示中添加它後,該應用程序無法安裝在設備中。它顯示「無法下載應用程序」對話框 – beck

+0

這與網絡有關,請嘗試刪除舊應用程序並重新啓動您的設備。 – Diamond

+0

還是一樣。我嘗試用我的軟件包名替換com.mycompany.myapp,但存在問題 – beck