Watching for Status Changes

Beginning with iOS 4.0, iOS devices gained the ability for multiple apps to run simultaneously on a device. This can create some complex behavioral bugs when dealing with state, especially if the user is accessing two different Game Center–enabled apps at the same time. For example, the user may log out of Game Center, or even log in as a different user, while your app is in the background. Therefore, it is vital that you listen for changes to the local user through the NSNotification system.

Add the following snippet of code in viewDidLoad of UFOViewController.m, right after the test is performed to verify whether Game Center is available.

[[NSNotificationCenter defaultCenter]                              addObserver:self ...

Get Beginning iOS Game Center and Game Kit: For iPhone, iPad, and iPod touch now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.