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 68030
 
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

Similar Threads
thread Thread Starter Forum Replies Last Post
iOS 7 Disables Screenshot Interruptions, Allows Users to Secretly Take Snapchat Screenshots MacRumors MacRumors.com News Discussion 119 Jun 29, 2013 01:05 PM
How do you manage AVCHD? AndyR Digital Video 47 Apr 11, 2013 11:38 PM
AirPort Express (2nd Generation) - AirPlay (over WiFi) lags / audio interruptions endrju83 Mac Peripherals 2 Feb 18, 2013 02:53 PM
What to use to Manage Website? doubledee Buying Tips and Advice 0 Feb 17, 2013 11:11 PM
iPhone 4S AirPlay to ATV2 text interruptions stevenoprea Apple TV and Home Theater 0 Nov 15, 2012 04:57 PM

Forum Jump

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

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

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