Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Alhazred

macrumors member
Original poster
Jul 5, 2011
35
0
I haven't understood if interruptions such as phone calls must be always managed or not.
My app do this:
- it shows a text field where the user insert a keyword
- tapping a button a request is sent to a php script on a webserver
- the app receives a text and a link to a picture from the php script
- the app shows the text and the picture (loading it from a website)
- the user can edit the text and send it to another php script which will save the edited text into a database

This is all what my app does, do you see in any of these operation the need to save data or to manage anything else if an interruption occurs?
 

chown33

Moderator
Staff member
Aug 9, 2009
10,764
8,463
A sea of green
- it shows a text field where the user insert a keyword
- tapping a button a request is sent to a php script on a webserver
- the app receives a text and a link to a picture from the php script
- the app shows the text and the picture (loading it from a website)
- the user can edit the text and send it to another php script which will save the edited text into a database

Underlined is where user-entered text should be preserved.

Also, there is program state (accepting keyword, retrieving picture and text, editing text) that should be preserved. You can tell the state is significant because the different states aren't interchangeable. You can't retrieve a picture and text until after a keyword is entered. You can't edit the text until after it's retrieved for editing.
 
Last edited:

Alhazred

macrumors member
Original poster
Jul 5, 2011
35
0
Thanks, I'm managing the interruption by using NSUserDefaults.

I have a question:
as I've understood I have to put the code to save the state inside the delegate method applicationDidEnterBackground() contained in the AppDelegate class, but how can I read from here the data in use on a view?

In the specific on a view I have 1 picture, 2 editable labels.
I can't use
self.label1.text to read the label value from the AppDelegate, so how should I do?
 

jnoxx

macrumors 65816
Dec 29, 2010
1,343
0
Aartselaar // Antwerp // Belgium
Thanks, I'm managing the interruption by using NSUserDefaults.

I have a question:
as I've understood I have to put the code to save the state inside the delegate method applicationDidEnterBackground() contained in the AppDelegate class, but how can I read from here the data in use on a view?

In the specific on a view I have 1 picture, 2 editable labels.
I can't use
self.label1.text to read the label value from the AppDelegate, so how should I do?

Why would u do self? because that's the AppDelegate.. You could refer to a pointer of your controller? or keep a singleton class, where u save everything. there are alot of possibilities..
 

Alhazred

macrumors member
Original poster
Jul 5, 2011
35
0
I think I got what you mean, but not how to put in practice.
I've done like this:
Code:
MyViewController *detail = [[MyViewController alloc] init];
[[NSUserDefaults standardUserDefaults] setObject:detail.label1.text forKey:@"savedLabel1"];
[[NSUserDefaults standardUserDefaults] setObject:detail.label2.text forKey:@"savedLabel2"];
but the values are null.
Can you explain me how to do?
 

jiminaus

macrumors 65816
Dec 16, 2010
1,449
1
Sydney
I think I got what you mean, but not how to put in practice.
I've done like this:
Code:
[COLOR=red]MyViewController *detail = [[MyViewController alloc] init];[/COLOR]
[[NSUserDefaults standardUserDefaults] setObject:detail.label1.text forKey:@"savedLabel1"];
[[NSUserDefaults standardUserDefaults] setObject:detail.label2.text forKey:@"savedLabel2"];
but the values are null.
Can you explain me how to do?

The code in red above is wrong. It's creating a new MyViewController object, that's why the values are null. You need to use a pointer to the current MyViewController object. Do you have a pointer to that object stored anywhere?
 

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
The view controller should save/restore its own state. It needs to register for the appropriate notification (UIApplicationWillResignActiveNotification for example). In the callback method just save the state however you like.
 

Alhazred

macrumors member
Original poster
Jul 5, 2011
35
0
The view controller should save/restore its own state. It needs to register for the appropriate notification (UIApplicationWillResignActiveNotification for example). In the callback method just save the state however you like.
Thanks, I've made it work with it. :)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.