Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jul 11, 2011, 09:21 AM   #1
Alhazred
macrumors member
 
Join Date: Jul 2011
Do I need to manage interruptions?

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?
Alhazred is offline   0 Reply With Quote
Old Jul 11, 2011, 09:46 AM   #2
chown33
macrumors 603
 
Join Date: Aug 2009
Quote:
Originally Posted by Alhazred View Post
- 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 by chown33; Jul 11, 2011 at 06:59 PM.
chown33 is offline   0 Reply With Quote
Old Jul 12, 2011, 06:04 AM   #3
Alhazred
Thread Starter
macrumors member
 
Join Date: Jul 2011
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?
Alhazred is offline   0 Reply With Quote
Old Jul 12, 2011, 06:10 AM   #4
jnoxx
macrumors 65816
 
jnoxx's Avatar
 
Join Date: Dec 2010
Location: Aartselaar // Antwerp // Belgium
Quote:
Originally Posted by Alhazred View Post
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..
jnoxx is offline   0 Reply With Quote
Old Jul 12, 2011, 06:27 AM   #5
Alhazred
Thread Starter
macrumors member
 
Join Date: Jul 2011
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?
Alhazred is offline   0 Reply With Quote
Old Jul 12, 2011, 06:50 AM   #6
jiminaus
macrumors 65816
 
Join Date: Dec 2010
Location: Sydney
Quote:
Originally Posted by Alhazred View Post
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?
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?
jiminaus is offline   0 Reply With Quote
Old Jul 12, 2011, 07:04 AM   #7
PhoneyDeveloper
macrumors 68020
 
PhoneyDeveloper's Avatar
 
Join Date: Sep 2008
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.
PhoneyDeveloper is offline   0 Reply With Quote
Old Jul 12, 2011, 07:31 AM   #8
Alhazred
Thread Starter
macrumors member
 
Join Date: Jul 2011
Quote:
Originally Posted by PhoneyDeveloper View Post
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.
Alhazred is offline   0 Reply With Quote
Old Jul 12, 2011, 08:22 AM   #9
jiminaus
macrumors 65816
 
Join Date: Dec 2010
Location: Sydney
Quote:
Originally Posted by PhoneyDeveloper View Post
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.
jiminaus is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
My 3GS is on 4.0 but I want to upgrade to 4.2.1 - What do I need to do? Snowscape Jailbreaks and iOS Hacks 2 May 1, 2011 01:54 PM
What do you use to manage your money? davidg4781 Mac Applications and Mac App Store 16 Aug 21, 2009 02:38 AM
Do I need to do anything to make Intelligent Keyboard to work? JoelMarcey iPhone 3 Jun 20, 2009 09:23 AM
Need your advice: Do I need to unjailbreak my iPhone to get it replaced it by Apple? Numl0ck iPhone Tips, Help and Troubleshooting 13 May 5, 2009 08:21 AM
What do you use to manage FONTS kenyabob Mac Applications and Mac App Store 5 Nov 15, 2003 10:10 PM


All times are GMT -5. The time now is 11:27 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC