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 12, 2011, 11:08 AM   #1
newtoiphonesdk
macrumors 6502a
 
Join Date: Jul 2010
Using a settings .plist to determine what website loads

I have an app that I want options of viewing audio or video podcast of our podcast. I don't want the clutter of a segmented controller or adding another control in the app so i decided i would do this by adding a settings bundle. I have it working, just with an issue of having to kill the app completely after changing settings to get different podcast to appear. Any suggestions for doing this without having to completely restart app?

I set up the plist with a PSMultiValueSpecifier and key of defaultTab. I set up an Array under this with Titles of Audio Podcast and Video Podcast, the values I made a string for testing of http://www.google.com and http://www.yahoo.com. In the viewController being used I have this as my viewDidLoad code:

Code:
- (void)awakeFromNib
{
	NSString *path = [[NSUserDefaults standardUserDefaults] objectForKey:@"defaultTab"];
	Reachability *reachability = [Reachability reachabilityWithHostName:@"google.com"];
	NetworkStatus status = [reachability currentReachabilityStatus];
	
	if (status == ReachableViaWiFi) {
		[sermons loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:path]]];
		reload.hidden=YES;
		sermons.hidden=NO;
	}
	
	else {
		UIAlertView *cancelled = [[UIAlertView alloc] initWithTitle:@"Wifi Required" message:@"To listen to the sermons, you must be connected to a Wifi Network.  After connecting to a Wifi Network, press the 'Reload Sermons Page' button (located in Sermons tab) to try again.  You may also download sermons via iTunes app from our official Podcast." delegate:self cancelButtonTitle:@"Open in iTunes" otherButtonTitles:@"Dismiss", nil];
		[cancelled show];
		[cancelled release];
		reload.hidden=NO;
		sermons.hidden=YES;
	}
	
	timer = [NSTimer scheduledTimerWithTimeInterval:(1.0/2.0) target:self selector:@selector(tick) userInfo:nil repeats:YES];	
}
This works for me, and it will use google.com as default, and I can change it in the Settings window, but here is where I run into a bit of an issue. If I do not kill the app in the multi-tasking bar, it won't change after I change it in the settings app. Once I completely kill the app, and restart it, it will load the different view. Is there a way I can make it change without having to kill app completely?
newtoiphonesdk is offline   0 Reply With Quote
Old Jul 12, 2011, 11:14 AM   #2
robbieduncan
Moderator
 
robbieduncan's Avatar
 
Join Date: Jul 2002
Location: London
awakeFromNib is only called when the object is de-serialized from the nib/xib file. This does not happen every time the app is shown/brought back from the background. Look at using a method of the UIViewController that will be called every time the view is displayed or an app delegate method that will be called when the application did become active.
robbieduncan is offline   0 Reply With Quote
Old Jul 12, 2011, 11:19 AM   #3
newtoiphonesdk
Thread Starter
macrumors 6502a
 
Join Date: Jul 2010
Quote:
Originally Posted by robbieduncan View Post
awakeFromNib is only called when the object is de-serialized from the nib/xib file. This does not happen every time the app is shown/brought back from the background. Look at using a method of the UIViewController that will be called every time the view is displayed or an app delegate method that will be called when the application did become active.
I had thought about using the viewWillAppear method, but then, everytime the user navigated away from that Controller and came back, it would go back to the default. As this webview would be showing a podcast, there could be a lot of issues if say, the user wanted to listen to a podcast, did something else, and wanted to pause it, but when they open the controller, it just goes right back to the original site.
newtoiphonesdk is offline   0 Reply With Quote
Old Jul 12, 2011, 11:22 AM   #4
robbieduncan
Moderator
 
robbieduncan's Avatar
 
Join Date: Jul 2002
Location: London
Quote:
Originally Posted by newtoiphonesdk View Post
I had thought about using the viewWillAppear method, but then, everytime the user navigated away from that Controller and came back, it would go back to the default. As this webview would be showing a podcast, there could be a lot of issues if say, the user wanted to listen to a podcast, did something else, and wanted to pause it, but when they open the controller, it just goes right back to the original site.
It would only do that if you programmed it to do that. There is nothing stopping you having a variable that holds the currently selected website from the settings.plist and in viewWillAppear check whether the currently selected on in settings.plist matches the variable. If it does don't change anything, if it does not update your view.
robbieduncan is offline   0 Reply With Quote
Old Jul 12, 2011, 11:45 AM   #5
newtoiphonesdk
Thread Starter
macrumors 6502a
 
Join Date: Jul 2010
Quote:
Originally Posted by robbieduncan View Post
It would only do that if you programmed it to do that. There is nothing stopping you having a variable that holds the currently selected website from the settings.plist and in viewWillAppear check whether the currently selected on in settings.plist matches the variable. If it does don't change anything, if it does not update your view.
Let me make sure I understand what you are saying. The viewWillAppear can be programmed to check if the value in the settings.plist has changed, and if it has it would reload to match the value, and otherwise do nothing?
newtoiphonesdk is offline   0 Reply With Quote
Old Jul 12, 2011, 12:24 PM   #6
robbieduncan
Moderator
 
robbieduncan's Avatar
 
Join Date: Jul 2002
Location: London
Quote:
Originally Posted by newtoiphonesdk View Post
Let me make sure I understand what you are saying. The viewWillAppear can be programmed to check if the value in the settings.plist has changed, and if it has it would reload to match the value, and otherwise do nothing?
Yes, you can program it to do that if you track what the existing setting is. It's up to you: programming is a creative discipline. Be creative.
robbieduncan is offline   0 Reply With Quote
Old Jul 12, 2011, 12:40 PM   #7
newtoiphonesdk
Thread Starter
macrumors 6502a
 
Join Date: Jul 2010
Quote:
Originally Posted by robbieduncan View Post
Yes, you can program it to do that if you track what the existing setting is. It's up to you: programming is a creative discipline. Be creative.
Thanks. This is my first time working with a custom plist file in one of my apps. How do you track the values of this?
newtoiphonesdk is offline   0 Reply With Quote
Old Jul 12, 2011, 12:43 PM   #8
robbieduncan
Moderator
 
robbieduncan's Avatar
 
Join Date: Jul 2002
Location: London
Quote:
Originally Posted by newtoiphonesdk View Post
Thanks. This is my first time working with a custom plist file in one of my apps. How do you track the values of this?
Read what I said above: store the value in a variable. Ensure the scope of the variable is such it will persist for as long as you need it. There is absolutely nothing plist specific in this at all.
robbieduncan is offline   0 Reply With Quote
Old Jul 12, 2011, 01:08 PM   #9
newtoiphonesdk
Thread Starter
macrumors 6502a
 
Join Date: Jul 2010
Quote:
Originally Posted by robbieduncan View Post
Read what I said above: store the value in a variable. Ensure the scope of the variable is such it will persist for as long as you need it. There is absolutely nothing plist specific in this at all.
I don't mean to be a pain, and I really am trying stuff out, but I am unsure how to store the value in a variable. I do understand the concept that I can store the value, and then in the viewWillAppear create a NSString for the objectforkey and then compare the two, and if they do not match, have it load the website for whatever the existing objectforkey value is. What I am lost at is how to store the original value in a variable. Am I making sense? Sometimes I can ramble and not get what I mean out.
newtoiphonesdk is offline   0 Reply With Quote
Old Jul 12, 2011, 01:30 PM   #10
chown33
macrumors 603
 
Join Date: Aug 2009
To store something in a variable, first you need a variable. So decide what variable name you want, what its type should be, and where it should be placed in the code. Then write the code to do that.

If you don't know where to place the variable, think about your options: it could be an instance variable in an object, a static variable outside any object, or a local variable in a method. The correct one to use depends on what lifetime you need for whatever gets stored in the variable. So think about the lifetime and where you need to access it from (called the variable's "scope").
chown33 is offline   0 Reply With Quote
Old Jul 12, 2011, 01:47 PM   #11
newtoiphonesdk
Thread Starter
macrumors 6502a
 
Join Date: Jul 2010
Quote:
Originally Posted by chown33 View Post
To store something in a variable, first you need a variable. So decide what variable name you want, what its type should be, and where it should be placed in the code. Then write the code to do that.

If you don't know where to place the variable, think about your options: it could be an instance variable in an object, a static variable outside any object, or a local variable in a method. The correct one to use depends on what lifetime you need for whatever gets stored in the variable. So think about the lifetime and where you need to access it from (called the variable's "scope").
I have never done anything like this before, so I am completely unsure where it would need to be placed. My guess would be an instance variable in an object so that I could store it in the viewController?

On a slightly different note, the first time I run the app, nothing loads in the webview at all. I believe this may be due to an error in my plist. Could you look at this and see if the DefaultValue needs to be changed to something else?
Code:
<dict>
	<key>StringsTable</key>
	<string>Root</string>
	<key>PreferenceSpecifiers</key>
	<array>
		<dict>
			<key>Type</key>
			<string>PSGroupSpecifier</string>
			<key>Title</key>
			<string>Podcast Type Selector</string>
		</dict>
		<dict>
			<key>Type</key>
			<string>PSMultiValueSpecifier</string>
			<key>Title</key>
			<string>Podcast Type</string>
			<key>Key</key>
			<string>defaultTab</string>
			<key>DefaultValue</key>
			<string>0</string>
			<key>Titles</key>
			<array>
				<string>Audio Podcast</string>
				<string>Video Podcast</string>
			</array>
			<key>Values</key>
			<array>
				<string>http://www.316apps.com/iphonesermons.html</string>
				<string>http://www.yahoo.com</string>
			</array>
		</dict>
	</array>
</dict>
</plist>

Last edited by newtoiphonesdk; Jul 12, 2011 at 02:07 PM. Reason: Different Issue
newtoiphonesdk 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
Website loads extremely slow on my mac, fast on iphone, ipad...etc compute Mac Basics and Help 0 Jan 19, 2014 02:59 PM
General: plist alternative to Slow Factor in Hidden Settings dasx Jailbreaks and iOS Hacks 4 Jan 6, 2014 11:16 AM
Website seems to hang while loading then randomly loads willmer Mac Basics and Help 0 Dec 9, 2013 12:03 AM
iPhone: Jukebox and editing plist settings EvanLugh Jailbreaks and iOS Hacks 0 Mar 3, 2013 12:23 PM
Website Export Settings Lightroom...? acearchie Digital Photography 3 Feb 9, 2013 06:13 PM

Forum Jump

All times are GMT -5. The time now is 03:56 AM.

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

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