Swift Azure Mobile QuickStart - Add and sync PNG image

纵然是瞬间 提交于 2020-02-06 08:25:07

问题


New to iPhone, Swift. Using XCode 9.3

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

The app uses: https://github.com/MicrosoftDocs/azure-docs/blob/master/articles/app-service-mobile/app-service-mobile-ios-how-to-use-client-library.md

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

Method: Convert the PNG to 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)

// 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 & 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.

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

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

Thanks for help


回答1:


Success !!

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

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

Purge table: Toitems

Hope this helps anyone learning Swift and Azure Mobile Service.



来源:https://stackoverflow.com/questions/49863145/swift-azure-mobile-quickstart-add-and-sync-png-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!