Archive

Posts Tagged ‘iPhone SDK’

Objective C: Read iPhone Preferences From Application

July 19th, 2009 No comments

You can read preferences from your iPhone Application using the NSUserDefaults class from iPhone SDK.

Here is how you can read the delay value before the phone is starting to dial a number

NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
delayBeforeDialing = [userDefaults floatForKey:@"delayBeforeDialing"];

The key, “delayBeforeDialing” in this example, needs to match the Key value in Root.plist.

There are different accessor methods depending on the type of variable you want to retrieve.

* arrayForKey
* boolForKey
* dataForKey
* dictionaryForKey
* floatForKey
* integerForKey
* objectForKey
* stringArrayForKey
* stringForKey

You don’t have to use a UI for your preferences. If you just want to conveniently store values associated with your application, that you can read back later, you can use the setter methods of NSUserDefaults.

Objective C: Show online image on iPhone

July 18th, 2009 No comments

By default the UIImageView control from the iPhone sdk does not allow us to load images from a specific url. In this case we do a little tryck and use a UIWebView.

- (void)loadImage:(NSString*)url frame:(CGRect)frame {
NSString* textHTML = @"
<!--
body {
background-color: transparent;
color: white;
}
-->
<img src="\" alt="" width="%0.0f" height="%0.0f" />
";
 
NSString* html = [NSString stringWithFormat:textHTML, url, frame.size.width, frame.size.height];
 
if(webView == nil) {
webView = [[UIWebView alloc] initWithFrame:frame];
[self.view addSubview:webView];
}
 
[webView loadHTMLString:html baseURL:nil];
}