2017-06-08 54 views
0

我也看到了很多與我的問題有關的堆棧溢出問題,我已經實現了他們提到的所有事情,但仍然無法正常工作。在標記重複之前,請仔細閱讀我完整的問題,並已實施所有必需的更改。canOpenURL正在失敗,但對Outlook的開放作品iOS

我想從我的應用程序打開Outlook郵件客戶端應用程序。請找到下面的代碼

let url = URL(string: "ms-outlook://[email protected]&subject=Mobile%20App%20Feedback") 
    if UIApplication.shared.canOpenURL(url!) { 
     UIApplication.shared.open(url!) 
    } 
    else 
    { 
      AppDelegate.sharedDelegate().getRootViewController().showAlert(title: "Cannot send email", message: "There is no Outlook app installed on your device device.") 
    } 

我還增加了MS-前景在我的plist了。

<key>LSApplicationQueriesSchemes</key> 
<array> 
    <string>ms-outlook</string> 
</array> 

我提示以下錯誤:

"This app is not allowed to query for scheme ms-outlook" 

我在真實的設備太測試。如果我刪除canOpenURL檢查並直接打開url工作正常。我不知道我錯過了什麼。提前致謝。

+1

[canOpenUrl - 這個程序是不允許查詢方案instragram]的可能的複製(https://stackoverflow.com/questions/32870393/canopenurl-this-app-is-not-allowed-to- query-for-scheme-instragram) – DonMag

+0

或...在你發佈的代碼中,'urlScheme!'是什麼?如果我用'.canOpenURL(url!)替換它'它工作正常 - 我得到了一個失敗的URL:「ms-outlook:// ...錯誤信息和'if'失敗(相對於'不允許查詢消息) – DonMag

+0

我已更新我的問題,輸入錯誤 – Warrior

回答

0

我推出了備用選項。

let scheme : String = "ms-outlook://[email protected]&subject=Mobile%20App%20Feedback" 

    if let url = URL(string: scheme) { 
     UIApplication.shared.open(url, options: [:], completionHandler: { 
      (success) in 
      if (success) 
      { 
       print("Open \(scheme): \(success)") 
      } 
      else 
      { 
       AppDelegate.sharedDelegate().getRootViewController().showAlert(title: "Cannot send email", message: "There is no Outlook app installed on your device.") 
      } 
     }) 
    } 
相關問題