PDA

View Full Version : Do I need to manage interruptions?




Alhazred
Jul 11, 2011, 09:21 AM
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
Jul 11, 2011, 09:46 AM
- 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.

Alhazred
Jul 12, 2011, 06:04 AM
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
Jul 12, 2011, 06:10 AM
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
Jul 12, 2011, 06:27 AM
I think I got what you mean, but not how to put in practice.
I've done like this:

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
Jul 12, 2011, 06:50 AM
I think I got what you mean, but not how to put in practice.
I've done like this:

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?

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
Jul 12, 2011, 07:04 AM
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
Jul 12, 2011, 07:31 AM
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. :)

jiminaus
Jul 12, 2011, 08:22 AM
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.

That's neat and tidy.