Store device token in AppDelegate, then use it in ViewController
<p>I am trying to get the device token in my AppDelegate, and then use it in a function in my ViewController later.</p>

<p>I successfully retrieve the device token like so in the AppDelegate:</p>

<pre><code>- (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{
    NSString *tokenAsString = [[[deviceToken description]
                                 stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"&lt;&gt;"]]
                                stringByReplacingOccurrencesOfString:@" " withString:@""];

    [[NSUserDefaults standardUserDefaults] setObject: token forKey:@"deviceToken"];
    [[NSUserDefaults standardUserDefaults]synchronize];
}
</code></pre>

<p>Then I am trying to use it in a function in my ViewController, but it is printing as <code>null</code>:</p>

<pre><code>-(void)addDeviceToken{
    NSString *deviceToken = [[NSUserDefaults standardUserDefaults] objectForKey:@"deviceToken"];
    NSLog(@"%@", deviceToken);
}
</code></pre>

<p>Does anyone know how to get the variable to show up here?</p>