I have an application that displays some graphics based on the properties of an object. I want that the state of that object to persist when the application is started next. I know that the app delegate has a "applicationwillterminate" function which I can use, but the problem is I have no idea how to get a hold of a pointer to the object.
I am trying to make this iphone app follow MVC principles, and I have the proper view and controllers. How does app delegates fit into the picture, and how can I use them? I read everywhere of advice saying to save application state during "applicationWillTerminate" but no concrete examples!
Can anyone point me to some literature or give me a hand?
Thanks!
See my answer to this question. If you need more help just let me know.
Related
I am new to swift.
I am now trying to implement crashlytics in to my app.
I have followed the tutorial to implement it for basic report but I want to implement userID so that I know who has problem using my app.
I have checked online and found setUserIdentifier function but I have no idea where to implement this function.
Do I need to call this function in every page or in app delegate.swift?
Please give me an example on how to implement this one function.
Thank you very much.
let phoneID = UIDevice.currentDevice().identifierForVendor.UUIDString
Fabric.with([Crashlytics()])
Crashlytics.sharedInstance().setUserIdentifier(phoneID)
I used this to solve the problem and get the phone id.
I would strongly discourage the #Jun-Luo 's approach of using UUUID.
Crashlytics.sharedInstance().setUserIdentifier("12345")
Crashlytics.sharedInstance().setUserEmail("mail#domain.com")
Crashlytics.sharedInstance().setUserName("AppUserName")
You can use any one of above to track the user. But its better to secure user privacy, hence all we need as a developer is a ID which we can easily tack back with our server side access.
Code Example
https://docs.fabric.io/apple/crashlytics/enhanced-reports.html
I know this question is already asked earlier also but i did not found any thing much useful. so asking again. I want to use the MVC architecture in accessing database from view controller. Till now the practice i was following, just creating database methods in delegate and access in view controller itself. But now i need to follow MVC pattern only as per company.
I have not found any proper tutorial to follow except apple website. I want some other where everything is described in detail and simple language to understand.
Please guide for above.
The best way for you is to use Core Data.
You can find a great tutorial here and there are many others tutorials about Core Data through the web.
Using Core Data you can access and modify your data base in every class on your app and in every view controllers using the manageObjectContext.
I create an application that retrieve data from websites(that's not mine) and save to core data. I want to create the notification when the new record have been inserted to my core data. I think the retrieve data method and add objects method should be run on the background but how can i do that? any sample code?
You really should build a basic understanding of multithreaded programming before you jump into this, and that's rather a bigger subject than we can reasonably cover in an answer. Start by reading Apple's documentation on the topic:
Threading Programming Guide
Concurrency Programming Guide
This isn't easy to do. Using Core Data in a background thread requires you to have a separate context for that thread. I'd suggest starting out by reading the Core Data Concurrency Guide. Also read the guides that Caleb linked to.
Once you figure out how to get your background context running, you'll most likely want to subscribe to the NSManagedObjectContextDidSaveNotification to update the UI on the main thread.
[self performSelectorInBackground:#selector(yourMethod:) withObject:];
You have to perform an async request [wich won't be performed on the main thread], and you will be notified about request completion/error/timeout in a delegate method, based on the library you are using.
I have experience with RestKit, you will find plenty of examples in the repository.
You mention creating a notification when inserting data into CoreData. Couldn't you just watch for the notifications sent by CoreData, like NSManagedObjectContextDidSaveNotification?
I'm in the process of the building a simple iphone application and I had a few questions.
I need to parse through results from an API key search, and manipulate them in my program. The API is from rotten tomatoes, and I can't find a parser that works with ARC. I know the JSON kit works well for previous versions of XCode, but I really like ARC and have done my application to date using it.
1) Is there a solid parser for such results or is it something I'm going to have to do manually?
The basic structure of my app includes a search page and personal list of things, using a mutable array of objects to populate a table view.
2) whats the best way to design the classes and implementation? I know this is a vague questions so let me be more specific. I have one object with several attributes, and I want to both access a remote server and rotten tomatoes API, and store local data internally. So I have my storyboad with a controller for each tab view (there are two). Then I have my object class. Do i need to create a controller specifically for it or can I manipulate (create and delete) in other controllers?
I can give some more specifics about the application, I'm just feeling a little overwhelmed as it is my first time working with Xcode. Any help would be appreciated.
May i suggest you the NSJSONSerialization Class., it should work well with ARC as it is compatible with iOS 5 and above.
Or you can set the ARC flag to no in .m files that you would like it to be switched off. For that purpose you can refer a great answer here.
You can set a compiler flag on the implementations that aren't going to be used in ARC.
Use: -fno-objc-arc
About the first question, you can turn ARC off on specific files, this allows you to mix ARC enabled with non-ARC enabled classes in the same project,
Please refer to the answer of this question
How can I disable ARC for a single file in a project?
About the second question
Do you have two different classes that access the same api services?
If yes i suggest that you create a common remote-request class, this class will do the request for you.
For example:
Let say we have class1 (for tab1) and class2 (for tab2)
And we have classCommonRequest(for both the requests)
App delegate will hold a reference to the classCommonRequest
class1 and class2 can both access this class by using
YourAppDelegate *delegate = (YourAppDelegate *)[[UIApplication sharedApplication] delegate];
//get your refrence of request handler class
MyRequestHandler *request = [delegate myRequestHandler];
//then use functions in it
[request fetchSth];
If your question was more specific i could give you better answers :)
I hope this helped anyway
I was thinking of writing some UIViewControllers to display the data in my Core Data stores while developing and testing an app.
I was thinking of something like this: A view controller that allows the user to select parameters to be passed into a fetch request, then a table view controller to list the fetch results, and finally a view controller to display the data in a particular entry from the fetch results.
Does anyone know of some open source code already similar to this, or a different approach I should take for monitoring my data?
NOTE: To clarify, I'm talking about a generic solution that could be put into any app using CoreData with minimal configuration.
Not a direct answer to your question but there is a new app in the mac app store which allows you to view and manipulate Core Data Stores. While it doesn't integrate in with your own app (and its not the cheapest software out there) you might find it helpful. I stumbled across it a few moments ago and thought of your question here.
http://itunes.apple.com/us/app/core-data-editor/id403025957?mt=12