I've been working on an app which includes messaging.
We've noticed that emoji characters are causing some issues.
I've updated the server database to support them, and everything is working fine on Android and the simulator but iOS is failing.
For some reason when you send multiple emojis only some of them arrive.
Our data syncing system packages everything into a tar ball which is then unpacked into storage and read into the database.
I think one of the following points is causing this encoding issue;
During the network transfer (unlikely since it's a binary file)
When writing to disk
When reading from disk
When writing to SQL
When reading from SQL
By downloading the container for the app and inspecting the db file I can see it's already been broken by the time it get's there, so I think it's either the file stuff or writing into SQL.
I also attempted the techniques described in this;
Unicode File IO in Codename One
At some point along the line encoding breaks. Make sure you don't use any of the problematic methods such as:
new String(byte[])
String.toByteArray()
OutputStreamWriter(OutputStream)
InputStreamReader(InputStream)
There are a few more but all of these can lose encoding. You'll need to narrow this down to the exact method that's failing for you.
I was experiencing the same problem myself. What fixed it for me was calling the following on iOS before I save the text in sqlite
NSData *data = [originalValue dataUsingEncoding:NSNonLossyASCIIStringEncoding];
NSString *goodValue = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
Related
In my iOS Swift application I have images stored as NSData in a Realm database. Now I want to combine these images (or a subset query of them) into a single ZIP file and make it available for further transfer via Airdrop, Email and so on.
I am fine with how to transfer and how to get them out of the database but I have no clue how to create a single ZIP file out of a bunch of NSData objects.
After changing some keywords in Google for the search, I found 2 interesting looking Libs/Frameworks I now will start investigating in.
ZIP from Marmelroy
and
ZipArchive
Both can be found on GitHub. I have no big experiences with both of them at the moment. But ZipArchiveseems to have options for NSDataSupport as this is already stated in the Readme
Zip-up NSData instances. (with a filename)
So this might be an indicator for me.
You could simply serialize and archive your images instead before AirDrop sharing. See AirDropSample.
I am having problem reading a file. I'm using MagicalRecord as my CoreData wrapper. I successfully save or update object. With my NSLog I can see it, everything is fine and I can use it in my database. But every time I want to see SQLite file with my application (I'm using Datum LE), file is empty. I cannot access that file directly within my Library folder in my app. I copy that file to my desktop and it is empty. What am I doing wrong? So once more, everything inside my iOS application works fine, I can see records being saved and I can fetch them normally.
You are clearly looking at the wrong file. If your app is saving (I assume, across app restarts), the date is definitely saved.
One way to find out is to NSLog the persistent store URL and check the referenced file.
I believe the issue you are encountering is the new default journaling mode that Core Data uses.
See this article
https://developer.apple.com/library/ios/qa/qa1809/_index.html
Basically your changes are not written to the .sqlite file, but are found in .sqlite-wal. HOWEVER, most SQLite reading apps I have tried blow away the -wal when you open the .sqlite, so good luck.
You could try changing the journaling mode for debugging purposes
I am new to use of ftp servers. Hence please be patient and if you have any suggestion please advice.
My problem is that I have to download files from FTP server to my ios application cache all in background thread and then decode it for its contents to display the data under several heads on the UI.
Now for this I understood that https://github.com/nkreipke/FTPManager provides me proper way of downloading file. Now my problem is that the file saved in server are in csv or xls format. How do I read contents for it? Is the data downloaded as a file in my ios app in a particular format which I then need to parse for contents. Basically, I don't have to display the file as is, but read its contents and then break them under several heads and display it on UI as various different parameters. Kindly throw any light on how to approach it. Any well written parsers for this case are welcome for learning purpose. Thanks!
Normally, contents downloaded from a server are in NSData format. If you already know that the content will be a data that can be converted to string, you can use
NSString *myCSVContents = [[NSString alloc] initWithData:theData encoding:NSUTF8StringEncoding];
to convert your downloaded contents to NSString and/or use
https://github.com/davedelong/CHCSVParser
to parse the CSV contents easily.
PS: This is a CSV example, but you can do the same with xls contents the same way using a proper parser library.
https://github.com/QuetzalMX/QuetzalXLSReader
I am trying to browse through the data written by Core Data in an iOS app I am developing.
After the app ran for a while, and I assume collected some data, I now wish to look through the data and see what was written.
I have tried getting and browsing the .sqlite file through getting the app container from the device (Xcode > Devices > myApp > Download Container...).
I got the db files, myAppDB.sqlite, myAppDB.sqlite-shm and myAppDB.sqlite-wal.
When trying to look through them, it seems like the .sqlite is an empty table (except maybe some generic CoreData/sqlite stuff), and the -wal file has all the info.
The thing is I was only able to know that the wal has useful data when opening it with TextEdit, which din't show it in a very readable way, and when I tried to use an SQLite Manager app I an alert saying the wal is encrypted and I am asked to put a password...
For what it matters, I am writing a framework which handles the db (the model file and the code for writing data is inside the framework), then I have this framework running in an app I am developing. This is the code I use to create the store from within the framework (using MagicalRecord):
NSBundle *frameworkBundle = [NSBundle bundleForClass:[self class]];
[MagicalRecord setDefaultModelNamed:#"myAppStore.momd" inBundle:frameworkBundle];
NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:#"myAppStoreDB.sqlite"];
[MagicalRecord setupCoreDataStackWithStoreAtURL:storeURL];
UPDATE: I managed to open the sqlite file with both Core-Data-Editor and CoreDataUtility but they both override and delete the contents of the .wal file, and show an empty table... It does have the model (entity names/properties etc.) but no data.
My wal file is 873KB but when I open the sqlite with one of these 2 tools it becomes 0Bytes...
tl;dr
How can I browse through the info written by Core Data of the app I am developing?
Well, for some reason I had to force not using WAL in my store (using #"journal_mode":#"DELETE" as explained here).
I then got only .sqlite file without the smh and wal files, and was able to open it and view the data using the 2 mentioned tools (Core-Data-Editor and CoreDataUtility).
My guess is that this is something to do with either the fact that I am dealing with CoreData from a framework (creating a moc, creating entities, saving etc.) and not from the application. Another guess is that it has something to do with the fact that I am using MagicalRecord.
Any insights regarding the cause would be appreciated...
I am downloading a mp4 file with my iOS app, it works fine using
NSData dataWithContentsOfURL
but i need to updated only if the file has been updated,
can I check the file headers? or what is the best way to determine if the file has been updated so I downloaded it again?
Thanks
You can access the metadata using the http HEAD request, as explained in this SO answer. You'll need to create some sort of parser to pick out the information you need, though. Note that this might not work with every server, depending on how it has been set up.
If you have control of the server yourself, I'd recommend using a php script to output the date the file has been last changed, which you would call before downloading the file.
Personally, I prefer placing a manifest file (usually a plist) alongside the file in question, as it can hold even more data, for example metadata for several files, the number of entries in a database and the like. A backdraw of this approach is that you'll need to keep this file up to date, though. But often, that is worth the while.
Lastly, as rckoenes has mentioned, dataWithContentsOfURL is not a very good way to download files, espcially large ones. You really should be using some sort of datamanager class, which manages a NSURLConnection.