Archive for 'iPhone'

Resources: Core Data

So not all that long ago we put together a list of resources for getting into the gritty details of SQLite for your iPhone data management needs. And as chances are you’ve heard, that’s all unnecessary now because the awesomeness which is Core Data will be available on iPhone OS 3.o. Sooooo, as soon as you can target OS 3+ only, it behooves you to get up to speed on it!

First off, here’s a brief concepts overview to get you started.

Then visit Cocoa Dev Central for the exceedingly worthwhile Class Overview and sample application walkthrough.

Then go trawl the mothership for Officially Sanctioned resources, starting with the Programming Guide.

As always, cocoadev is a great resource for anything related to Cocoa, and Core Data is no exception.

A variety of interesting Core Data posts at Cocoa With Love.

And another good collection at Cocoa Is My Girlfriend.

And speaking of CIMGF, the great folks at Pragmatic (have you got their Core Animation book yet?) are bringing out a book on Core Data in the near future by Marcus Zarra of that blog, and based on what we’ve seen from all involved so far we’ll just go out on a limb here and recommend that you’re absolutely certain to find it invaluable and you should just click the picture and preorder it NOW!


[EDIT: And there's a new tutorial series starting here that looks worth following as well.]

Continue Reading →

Tutorial: JSON over HTTP

We’ve mentioned the json-framework project before; but here’s an excellent tutorial on how exactly to use it that you really should not miss if that’s something you need to do.

Also note this other alternative, ObjectiveResource, which handles both XML and JSON deserialization in the context of interacting with Ruby on Rails applications, a port of Ruby’s ActiveResource apparently…

h/t: iPhoneKicks!

Continue Reading →

Snippet: Orientation

Here’s a useful post on dealing with interface orientation changes:

One of the features with which I had to get fairly intimate with on the iPhone over the last couple of months was working with orientation changes. At first my code was completely incorrect and it wasn’t immediately obvious to me how to get my application to reorient itself properly. This was mainly due to the structure of my code. In this post I am going to explain a simple, memory efficient way of working with UIViewController and interface orientation changes.

We draw your attention particularly to the ‘Pitfalls’ discussion:

… I did have an issue where I was using 3 view controllers. Let’s call them A, B and C. A switched to B and vice-versa when the phone’s orientation changed. C was loaded by B and was viewable in landscape and portrait orientations. The problem came in where if you changed C’s orientation and then the user navigated back to B where B had a different orientation, you would effectively not be notified of an orientation change. If you subsequently changed B’s orientation to load A, you would find A would load in the wrong orientation. Oops, bug…

So how did I solve this? Well all I did was put this piece of code in A so that it would manually reorient itself from portrait to landscape:

- (void)viewDidAppear:(BOOL)animated {
		[UIView beginAnimations:@”View Flip” context:nil];
		[UIView setAnimationDuration:0.5f];
		[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
		self.view.transform = CGAffineTransformIdentity;
		self.view.transform = 
			CGAffineTransformMakeRotation(MPI * (90) / 180.0);
		self.view.bounds = CGRectMake(0.0f, 0.0f, 480.0f, 320.0f); = CGPointMake(160.0f, 240.0f);
		[UIView commitAnimations];

That’s a handy little snippet to keep in mind, indeed.

h/t: iPhoneSDK!

Continue Reading →

Tools: Shark

So if you’ve been doing Mac programming for a while, you’re probably aware that Shark is a tool of veritably godlike omniscience when it comes to profiling your application and finding out just what it is that needs optimization. But were you aware that you can do on-iPhone application profiling with it as well? 

Well, maybe you were, but we weren’t. And if you weren’t either, here’s how you do it to get all the source codey goodness of Shark handily:

1) Run your application from within Xcode on the device.

2) Start up Shark (/Developer/Applications/Performance Tools/ is where it lives).

3) Select “Network/iPhone Profiling…” from the Sampling menu.

4) Sort out the resulting dialog as explained here so it looks like this:


Note that this demonstrates Vital Tip #1: Select the particular process of interest, do NOT leave ‘Target’ atthe default of ‘Everything’. We tried that at first, since hey it’d be neat to see the complete list of what’s going on, logged for about 40 seconds … and eleven hours later, it was still chugging away with “Shared devices processing samples” without even having figured out how much work there was to do to get the progress bar started. Yeah, alright then, we won’t do that, will we.

After sorting that out, it’s a matter of a few minutes to get what looks like all the same information from your iPhone app that you can for your desktop apps. It’s amazing what you can find if you just think to actually look, isn’t it now?

Continue Reading →

UIWebView tips

Here’s a useful collection of tips on using UIWebView:

- Loading the SVG file from your resources folder
- UIWebView loading contents when it is off-screen
- Calling a javascript function from Objective-C
- Javascript communicating back with Objective-C code
- Disabling the selection flash
- Disabling the “action” pop-up
- Disabling default zoom effect

Something there for everybody. And here’s one more:

Common problem, need to apply nice HTML formatting for a section of your page, but want the UIWebView not to appear as a big white box – only the content of the UIWebView to appear. How to do it?

myWebView.opaque = NO;
myWebView.backgroundColor = [UIColor clearColor];
[myWebView loadHTMLString:
@"<html><body style='background-color: transparent'>
       Content Here</body></html>" baseURL:nil];

Now you know!

Continue Reading →

Screen Capturing

Thinking of making a video of your iPhone application running like it seems all the cool kids are these days? Well, if you don’t want to fool around with real video, here’s a couple tools that make screen capture more elegant so you can produce said video using the simulator: SimFinger and PhoneFinger!


[EDIT: And for the screen capture itself, here and here are experiences using ScreenFlow ... but if you have any comments for or against the many other Mac screen capture programs out there, feel free to share!]

Continue Reading →

Code: Reachability

Whoops, here’s something we’d overlooked in our latest app effort — good thing we stumbled across this before submitting it! — if your application is network dependent, apparently Apple requires that you detect network availability proactively, spinning helplessly in its absence is not sufficient. From this top 11 list of rejection reasons:

6. Popup for network detection If your app requires the use of the Internet, you must detect when the network is unavailable and provide a pop-up message informing the user. Just having the spinning busy icon display and a message saying “trying to connect” is not sufficient. Apple will reject your app if you don’t provide a message informing the user that they need a network connection.

Ah, OK then. No worries, we’ll just grab the Reachability sample … wait, what?

7. False claims of a missing network On a related note, make sure you don’t have any false positives in your network detection. There’s a bug in the “reachability” functions provided by Apple. If you don’t first try to perform a network connection but instead just do a reachability test, the code will always report the network is unavailable. Apple will reject your app if they discover you have this false positive case.

Actually, it looks like what I presume is the “bug” referred to above in Reachability is indeed not such … not exactly, anyways. The trick is, you want your first status check of your target host name’s reachability to be made synchronously. Because, until it completes the check, well, it’s not connected, is it now? Quite logical, really. And once that initial check is sorted, then your updates should properly be asynchronous. So in Reachability’s appDelegate where it has

[[Reachability sharedReachability] setHostName:[self hostName]];
// The Reachability class is capable of notifying your application when the network
// status changes. By default, those notifications are not enabled.
// Uncomment the following line to enable them:
//[[Reachability sharedReachability] setNetworkStatusNotificationsEnabled:YES];
[self updateStatus];

that’ll always return false for your target host reachability in -updateStatus if you follow the given instructions. Whoops! To fix that, simply do a synchronous then an asynchronous query

[[Reachability sharedReachability] setHostName:[self hostName]];
[self updateStatus];
[[Reachability sharedReachability] setNetworkStatusNotificationsEnabled:YES];
[self updateStatus];

… and you’re all good.

It would be more clear that the first host reachability check failing was a foreseeable occurrence if -setNetworkStatusNotificationsEnabled was actually labelled -setStatusResultsAsynchronous. Or, even better,
-callThisToMakeTheSampleFailHaHaSucka. But Apple very rarely labels sample code quite that honestly!

Continue Reading →

Testing: Squish!

Something to keep your eye on here: An upcoming GUI testing tool for your Cocoa Touch applications! Yep, the most deliciously named froglogic is promising a version of their Squish testing tool by “the upcoming Squish 4.0 release”, whenever that is.

Squish is a professional, cross-platform GUI and regression testing tool that enables testers to create and execute automated GUI tests for applications based on a variety of different GUI technologies. This includes applications based on Nokia’s Qt, Mac OS X Carbon and Cocoa, Java SWT/Eclipse RCP, Java AWT/Swing, Web/HTML/AJAX, and many other UI technologies. Squish stands out from other GUI test tools thanks to its close integration with each supported GUI technology—a feature which helps ensure that tests created with Squish are very robust and stable.

That’s quite the feature set, isn’t it now. Any of our Gentle Readers have any experience with Squish on this plethora of other platforms and have an opinion of how exciting this news actually is?

h/t: Jeff!

Continue Reading →

Code: L0SolicitReview

Well, this is an innovative approach to the problem of getting good reviews on the App Store: just go ahead and ask for them!

We all agree that having JUST negative solicitation (that is, Apple’s rate-on-delete) is bad, whether we agree or not that having it is a good thing (I think it is). What we lack is a way to solicit positive reviews from satisfied users to counteract the rate-on-delete ratings slump.

Well, here it is:

Find it on Google Code as part of the author’s UIKitPlus project; dunno if it will actually help with the negative selection problem … but it very likely isn’t going to hurt. One can hope.

h/t: iPhoneSDK!


Here’s another class for the prompt for reviews and ratings kind of thing:

Presenting, Appirater

Continue Reading →

Tip: iPhone Serial Number

So isn’t it annoying that when you need somebody’s iPhone ID for setting them up for Ad Hoc distribution and the like, there’s no way to easily copy it from iTunes? Well, here’s a handy way to get it as text. Plug it in, and have them go to and enter

system_profiler SPUSBDataType | grep 'Serial Number'

and just tell them to copy the text that appears!

Serial Number: eb2342b2feh5209e845fa7428e60f27a5ef93b7d

Ah, that’s much easier than relying on screenshots or questionable transcription abilities, isn’t it now?

[EDIT: Well, ok then ... apparently sometime since I did my first provisioning, iTunes got smart enough to actually copy the phone's ID when displayed. See first comment. My, you readers are so clever!]

[EDIT 2: No, wait -- there's actually an app, Ad Hoc Helper, from the redoubtable Erica Sadun up on the App Store for free to have your intended tester just email it to you directly. There you go. Brandon wins for that tip!]

Ad Hoc Helper

Continue Reading →
Page 80 of 98 «...5060707879808182...»