如何将 iOS 数据发送到 Azure 移动服务数据库?

How to send iOS data to Azure mobile service database?

我是 swift 和 Azure 的新手,我正在尝试将一些数据从我的 swift 应用程序发送到我的 azure 移动数据库。我有一个可以运行 CoreData 的应用程序,但在获取我的数据后,我 运行 遇到了将其发送到 azure 的困难。我正在尝试使用 Azure 框架中的 insert table 方法。

我试过这个方法:

let client = MSClient(applicationURLString: "https://mymobileapp.azure-mobile.net/", applicationKey: "aAaBbBcCc…")

var client = AppDelegate().client // To reference my constant in AppDelegate.swift

var itemTable:MSTable = client.tableWithName("Item")
var itemToInsert:NSDictionary = ["text":"My Awesome Item 1"]

itemTable.insert(itemToInsert,
    completion: {
        insertedItem, error in
        if error{
            println("error: \(error)")
        }
        else{
            println("Success!")
        }
    }
)

但我 运行 遇到了应用程序密钥的问题。据我所知,应用程序密钥不再用于 Azure 移动应用程序。

我也尝试了 swift 的移动应用程序快速入门指南中显示的方法,但该代码似乎适用于 swift 的旧版本。

我并不是要在我的应用程序中显示 table,只是将数据上传到数据库。如有任何帮助,我们将不胜感激!

我最终让它开始工作。应用程序密钥不再用于新的 Azure 移动应用程序。除了删除密钥之外,您还必须添加新的 属性,特别是 App Transport Security 属性,以允许与不安全的 HTTP 站点建立连接。

let client = MSClient(applicationURLString: "https://mymobileapp.azure-mobile.net/")

var client = AppDelegate().client // To reference my constant in AppDelegate.swift

var itemTable:MSTable = client.tableWithName("Item")
var itemToInsert:NSDictionary = ["text":"My Awesome Item 1"]

itemTable.insert(itemToInsert,
    completion: {
        insertedItem, error in
        if error{
            print("error: \(error)")
        }
        else{
            print("Success!")
        }
    }
)