tags:

views:

586

answers:

1

I have a navigation controller based iPhone app. I am using remote notifications and need to pass in the device token from registering via this code in the AppDelegate:

- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken {
NSLog(@"registered");
NSLog(@"dev token desc = %@", [devToken description]);

}

to the RootViewController.

Seems simple but given the wiring is done in the .xib files it's not clear how to implement. Any suggestions?

A: 

If you have a RootViewController, then I assume you're working with the navigation application template. If so, it's pretty easy. Off the bat, your app delegate only knows about the navigation controller, but it's easy enough to get an ivar that references the RootViewController.

  1. In your app delegate, declare IBOutlet RootViewController *rootVC. You can make it a property if you like.
  2. Open MainWindow.xib in Interface Builder and switch the view mode to list. Select the application delegate object (likely the third item in the list) and bring up its connections inspector (cmd-2)
  3. Back in the document window, the navigation controller should have a disclosure triangle. Click it to spin it open and reveal its children. It contains a navigation bar and the RootViewController.
  4. Connect the app delegate's rootVC outlet (in the connections inspector) to this RootViewController icon.

Now your app delegate can access methods and properties of the RootViewController. So you could give RootViewController a devToken property or a -(void) setDevToken: method or whatever.

invalidname
sounds good, i'll try it out tonight.
phil swenson