错误初始化 AZSCloudStorageAccount Swift 3

Error initialize AZSCloudStorageAccount Swift 3

我尝试 link 使用此代码进入我的帐户

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) .

谁能帮帮我。

the app crash without error, only (lldb) .

很抱歉 SWIFT blob 客户端目前没有提供任何错误处理代码。我会根据你的代码提供一些线索来跟踪你的问题。

  1. 在构建存储代码之前,在项目中进行一项更改。转到 'Azure Storage Client Library' -> Build Settings,搜索 "Defines Module" 设置,并将其更改为 'YES'.
  2. 请检查是否是网络连接问题导致的问题。
  3. 您可以通过将代码放在 do-catch 代码块中来获取此问题的错误代码。
do {
    //put your code here
} catch let error as NSError {
    print("Error code = %ld, error domain = %@, error userinfo = %@", error.code, error.domain, error.userInfo);
}
  1. SWIFT blob 样本已经过测试,针对 iOS 9.0 并使用 XCode 7 运行良好。如果您有不同的设置,样本可能不会 运行 适当地。我建议您使用 Blob Storage REST API 作为解决方法。

你的错误是这样的吗? 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)

Code=1是AZSEInvalidArgument,表示你的连接字符串无效。我有点困惑为什么你说 "the right path",因为 fromConnectionString 直接获取字符串,而不是文件路径。要查看正确连接字符串的示例,请参阅 Getting Started Guide。基本上它看起来像这样: "DefaultEndpointsProtocol=https;AccountName=your_account_name_here;AccountKey=your_account_key_here"

我们会尽快正确记录错误代码。抱歉造成混淆!