私のiPhoneアプリでは、以下に示すように、Delegateファイル内のパブリックプロパティを割り当てているAppleからデバイストークンを取得しています。
- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
{
self.dToken = [[NSString alloc] initWithData:deviceToken encoding:NSUTF8StringEncoding];
}
dTokenプロパティは、次のように宣言されます。
NSString *dToken;
@property (nonatomic,retain) NSString *dToken;
しかし、別のファイルからデバイストークンを取得しようとすると、null値が取得されます。
+(NSString *) getDeviceToken
{
NSString *deviceToken = [(MyAppDelegate *)[[UIApplication sharedApplication] delegate] dToken];
NSLog(@" getDeviceToken = %@",deviceToken); // This prints NULL
return deviceToken;
}
私は何が間違っているのですか?