Advice and tips on a data-driven iPhone app - iphone

I'm doing a little iOS app for the subway of my city. It has the following features
See the map (takes you to a UIImageView to see the map of the stations)
See status (tells you if there are problems with one of the lines/stations)
See prices (tells you the different tariffs, depending on the hour)
Subway-news (little feed with the title and the first paragraph of each article, with a link to see more in safari)
Our promotions to you (takes you to a view with image-coupons shown in a overflow fashion. If you click them, you go to a certain page)
I have a server that takes the news and encode them in JSON. From the iPhone, I request the JSON async, parse it and store the info in an NSArray of NSDictionaries (with keys: date, title, content, seeMoreUrl)
This could be bought as a little RSS feed. I saw some examples and they used a SQLite db to store the data. I'm not sure how necessary would this be, as I'm only planning on showing the 5 latest news and I'm not loading the whole content, just title and a iPhone-designed paragraph.
I have serious doubts with the promotions tough. I would request a file called promotions.json with the url of each promotion and the url they link to, like this
[
{
"imgSource":"http:\/\/www.domain.com\/promotions\/1.png",
"url":"http:\/\/www.domain.com\/freeRide"
},
{
"imgSource":"http:\/\/www.domain.com\/promotions\/54.png",
"url":"http:\/\/www.cheapCarRental.com\/promotions-to-subway-users"
}
]
Then, I don't know what to do. Should I download all images to the documents folder and then when the users click in view promotions, load every pic I found in that directory intro the coverflow-like View?
Should I implement a SQLite for the news and also use it to store the images as BLOBs?
Should I just keep them in memory?

You could save the images to the Library/Caches folder (Apple won't like saving to Documents folder without good reason - my app was rejected because of this. See guidelines.). Then, you have a cache file, which is essentially a plist that saves the url (the key) and the path of its corresponding image saved on the disk (the value).

What do you want your app to do? What will users want the app to do? Would they prefer to pay the price in terms of data usage and battery usage to download all the images and probably get a snappier user experience, or would they prefer occasional lags in the interface as images are downloaded on demand in return for longer battery life and decreased data usage? It's up to you to balance those factors.

Related

Saving screenshot to CoreData

I'm developing an app that I want the user to be able to take a screenshot with a button (this works, but it's stored to camera roll). I have a need to keep history of these screenshots along with site name, etc.
I've been reading that it's not recommended to save binary data in a sqlite db, so I've stumbled across core data. I'm still learning, but one question that comes to mind is this. Some recommend to save the filename to coredata and then save the image to document directory. I want to read the data back into a table view controller and have the image part of the cell. Will I need to resize the image to the size I want when reading in, or will it automatically size down to what it needs?
Also, when saving to document directory, are those files accessible from the camera roll? I don't want them to be and I'd like to give the user the ability to be able to delete them with the tableviewcontroller.
Please let me know if I need to expand on anything. I'm learning Swift, so I'm sure I missed something.
You should not save it to the Documents directory.
You should instead Allow External Storage of the attribute. Core Data will take care of storing it for you. This is explained in the answer by jansenmaarten to this question.

UITableView survey app and append data to apple numbers

Ive tried to search up documentation and several tutorials but it seems like there's nothing out there. Maybe this is something simple to do, but I just cannot figure it out.
My goal is to make an application that has a series of questions that you fill in. Some tick boxes and some text fields where you fill in some more info. This survey would be on one VC and you scroll down through the questions. After all this I want to append the data to the apple numbers app on the iPad with a specific structure.
How would I go about this? Any resources you can recommend?
T.I.A
I believe that you should generate and export a .csv file with all the data you collect in the app. Save that file to iCloud Drive or to another cloud solution you can integrate in your app, and then access it and open it using Numbers.

Clear SDWebImage Cache

I'm working on an iPhone app which has a news feed. This news feed is pulled from a JSON web service I've written (currently living on MAMP on my laptop).
Anyway, I use a MySQL DB to store references to my images, which are stored in the apache filesystem.
I store them in a very particular way, and this is how I store them:
Full Images: ng_(postid)_(seqid)
Thumbs: tng_(postid)_(seqid)
PostID is the unique ID that is assigned to every news post.
SeqID is an ID that is only unique for the photos for that news post.
I probably didn't make that very clear... example:
The images files in the first post might look like this
ng_1_1.jpg
ng_1_2.png
ng_1_3.jpg
The image files for the second post might look like this
ng_2_1.jpg
ng_2_2.png
ng_2_3.gif
This has worked great up till now, but I tried to see what would happen if I deleted a post, and recreated one in it's place?
Let's say we have a post called 'Old Post', which has 2 images, with a postid of 7.
It's images might look like this:
ng_7_1.jpg
ng_7_2.jpg
Let's say we deleted that post, and then created a new one afterwards, which has three images and is called 'New Post'.
It's images will look like this:
ng_7_1.jpg
ng_7_2.jpg
ng_7_3.jpg
Now, here comes the problem... If the device has viewed the old post, which was deleted, and then views this new post, they will see the first two images as the ones from OLD POST. Not the new ones.
Why? SDWebImage thinks because the URL is identical, and therefore decides to pull the cached image from disk. It doesn't even display the cached version, and then check if the image has been updated.
So, I've worked out there are two possible solutions to this:
Somehow get SDWebImage to check the online image, after displaying the cached version
Pass down a key in my JSON, to tell my app to wipe SDWebImage's cache (when necessary)
So, my question is, how would you go about deleting SDWebImage's cache, or making it check the server after displaying the cached version?
I think your PostID values are not unique in your system and that causes you problems. If you had unique PostID values it would be impossible to delete a post with given ID and assign that ID value to a new post...
PostID shouldn't be reusable in my opinion - can you imagine a clerk deleting a specific order in his system, creating a new one with old ID and one day getting a call from customer that provides his order ID which is now overwritten in the system?
Other thing is that you should never ever delete cached images on client's side - be user-friendly, save bandwidth and users' data plans (check this link why that matters). However you can specify cacheMaxCacheAge for SDWebImage to get rid of old, unused images. You can also remove specific images using removeImageForKey: when for example user decides to delete a specific post on his device.
Finally, the case you're describing relates more to updating a specific post, so posts can get different image set for example. In that scenario the simplest thing you can do is to use unique images IDs, so when a post is downloaded, new images will be downloaded (old ones will be deleted when cache reaches its max age - look for cacheMaxCacheAge). Alternatively, you could introduce a kind of synchronization mechanism in your DB/JSON (e.g. based on timestamps: if a post is downloaded and has a newer timestamp than the post stored in application cache, you remove old resources and download new images, text, etc... If timestamps are equal you're good with data you already downloaded).
An advanced solution would use RestKit and Core Data which would enable users to browse your posts offline and update content (images, text) when your web resource (JSON) changes.
What an epistle... I just hope my comments are useful for you :)

How can I edit PDF files in an iOS application?

In my iPhone / iPad application, I show a person's medical reports in the form of a PDF. I have saved the reports in the documents directory and am reading them from there.
I want the user to be able to add or edit comments on these PDFs, as well as be able to highlight certain sections in the PDF. After editing, the application should be able to save the PDF back into the documents directory.
Is this possible within an iOS application? If so, how? Is this a task for Core Graphics?
Editing PDF directly on iPad/iPhone is a rather big job because the standard API only supports showing it (and only a bit more.) If you want to do anything more, you need to invest a huge amount of time to implement generic pdf handling code.
There is an open-source library handling these, e.g. this one. I don't know if it fits your needs, though.
A better idea, in my opinion, is to create a native UI showing the data contained in the PDF file using the standard Cocoa-Touch UIKit and create the PDF once the user is done with it so that the user can export it back. That way, you don't have to write a complicated PDF handling code.
In any case, it's not a good idea to show generic PDF on iPhone, because the screen size is so small (iPad is a different question, especially if you expect the user to be familiar with the particular format of your pdf.). A dedicated UI would be much better.

Is URL obtained from UIImagePickerControllerReferenceURL stable?

I get the Asset Library URL for a photo using the UIImagePickerControllerReferenceURL key on the info dictionary obtained from UIImagePickerController. The url looks like this:
assets-library://asset/asset.JPG?id=1000000002&ext=JPG
Is this URL stable? Can I expect to save it in a document and then at a later date fetch the photo using this URL?
I basically have a iOS photo editing app where I allow the user to do some editing on a bunch of photos. I allow the user to save the project and edit at a later date. I would save these URLs to save the information about which photos are used in the project. I don't want to copy and save all the photos used in a project since there can be many photos used in a project and this will result in unnecessary duplication.
Can you also suggest if there is a better way around.
Asset URLs are supposed to be stable but the format changed between iOS3 and iOS4 and the format in iOS5 is something like '/asset/FA8F1400-82A5-424F-A98C-2883754FA54D.jpg'. You shouldn't store asset URLs and expect them to remain valid forever, which is a shame because that is exactly what you would expect.
You could protect yourself by storing the asset's date and maybe location if it is set. Then if your app needs to, it can go through the asset library and patch up the references if the URL format changes again.