2017-05-08 49 views
0

我試圖鏈接到我的帳戶與此代碼錯誤初始化AZSCloudStorageAccount斯威夫特3

let storageAccount : AZSCloudStorageAccount; 

       try! storageAccount = AZSCloudStorageAccount(fromConnectionString: config.getAzureConnection()) 

      let blobClient = storageAccount.getBlobClient() 
      var container : AZSCloudBlobContainer = (blobClient?.containerReference(fromName: config.getContainer()))! 

的「config.getAzureConnection()」中包含了正確的道路,因爲我使用的Android應用程序是相同的。

在這一行try! storageAccount = AZSCloudStorageAccount(fromConnectionString: config.getAzureConnection())應用程序崩潰沒有錯誤,只有(lldb)。

有人可以幫助我。

回答

1

你的錯誤是這樣嗎? fatal error: 'try!' expression unexpectedly raised an error: Error Domain=com.Microsoft.AzureStorage.ErrorDomain Code=1 "(null)": file /Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-802.0.53/src/swift/stdlib/public/core/ErrorType.swift, line 182 (lldb)

代碼= 1是AZSEInvalidArgument,這意味着您的連接字符串無效。我有點困惑你爲什麼說「正確的路徑」,因爲fromConnectionString直接接收字符串,而不是文件的路徑。要查看正確連接字符串的示例,請參閱Getting Started Guide。基本上看起來是這樣的: "DefaultEndpointsProtocol=https;AccountName=your_account_name_here;AccountKey=your_account_key_here"

我們將盡快記錄錯誤代碼。對困惑感到抱歉!

+0

謝謝你的幫助。 – HideCode

+0

非常歡迎! –

0

應用程序崩潰沒有錯誤,只有(lldb)。

我很抱歉,SWIFT blob客戶端目前沒有提供任何錯誤處理代碼。我會根據您的代碼提供一些線索來跟蹤您的問題。

  1. 在構建存儲代碼之前,請對項目進行一次更改。轉到「Azure存儲客戶端庫」 - >「生成設置」,搜索「定義模塊」設置,並將其更改爲「是」。
  2. 請檢查問題是否由網絡連接不良造成。
  3. 通過將代碼放入執行代碼塊中,可以獲得此問題的錯誤代碼。
do { 
    //put your code here 
} catch let error as NSError { 
    print("Error code = %ld, error domain = %@, error userinfo = %@", error.code, error.domain, error.userInfo); 
} 
  • 的SWIFT團塊樣品已經過測試並很好地工作中定位iOS 9.0和使用的XCode 7.如果你有不同的設置,樣品可能不運行正常。我建議您使用Blob Storage REST API作爲解決方法。