Swift Azure Mobile快速入门-添加并同步PNG图像 [英] Swift Azure Mobile QuickStart - Add and sync PNG image

查看:87
本文介绍了Swift Azure Mobile快速入门-添加并同步PNG图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

iPhone新手,Swift.使用XCode 9.3

New to iPhone, Swift. Using XCode 9.3

我正在尝试修改Azure QuickStart iPhone Swift应用程序以包括Images.xcassets PGN图像.

I am trying to modify the Azure QuickStart iPhone Swift app to include an Images.xcassets PGN image.

该应用使用:我只想使用1个Azure Sql Server表,而不要使用Azure BLOB存储.

I only want to work with 1 Azure Sql Server table and NOT use Azure BLOB storage.

方法:将PNG转换为Base64字符串

Method: Convert the PNG to Base64 String

快速代码更改 1. QSTodoDataModel.xcdatamodeid-添加的属性:pic,类型:String 2.将PNG转换为Base64 String

Swift code changes 1. QSTodoDataModel.xcdatamodeid - Added Attribute: pic, Type: String 2. Convert the PNG to type Base64 String

let myPicUI = #imageLiteral(resourceName: "apic")
 // ** Also tried: let myPicUI : UIImage = UIImage(named: "apic")!

 let myPicNSData : NSData = UIImagePNGRepresentation(myPicUI)! as NSData
 let myPicstrBase64 = myPicNSData.base64EncodedString(options: 
NSData.Base64EncodingOptions.lineLength64Characters)

//创建NSDictionary INSERT记录-

// Create NSDictionary INSERT record -

let itemToInsert = ["pic" : myPicstrBase64,  "text": text, "complete": 
false, "__createdAt": Date()] as [String : Any]


 UIApplication.shared.isNetworkActivityIndicatorVisible = true
    self.table!.insert(itemToInsert) {
        (item, error) in
        UIApplication.shared.isNetworkActivityIndicatorVisible = false
        if error != nil {
            print("Error: " + (error! as NSError).description)
        }

App Save&同步失败:添加了用户输入的文本"字段值,并在表格视图中显示.当尝试通过下拉表格屏幕同步到AZURE时,记录从表格视图中消失.直接查询Sql Server ToDoItem表,未插入任何记录.

App Save & Sync Failed: The User entered "text" field value is added and displays in the table view. When attempt to SYNC to AZURE via pull down table screen, the record disappears from the table view. Querying Sql Server ToDoItem table directly, no record inserted.

测试:直接使用字符串"TestString"时,移动同步成功

Test: Mobile Sync Successful when directly using String: "TestString"

let itemToInsert = ["pic" : "TestString",  "text": text, "complete": false, "__createdAt": Date()] as [String : Any]

感谢帮助

推荐答案

成功!!

转换为字符串:let myPicstrBase64 = myPicNSData.base64EncodedString()

Convert to String: let myPicstrBase64 = myPicNSData.base64EncodedString()

我正在使用免费的Azure Sql Server数据库. XCode错误输出窗口显示数据库无空间消息.

I am using the Free Azure Sql Server DB. The XCode error output window displayed database no space message.

清除表:项目

希望这可以帮助任何学习Swift和Azure移动服务的人.

Hope this helps anyone learning Swift and Azure Mobile Service.

这篇关于Swift Azure Mobile快速入门-添加并同步PNG图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆