我有一個NSString,作爲如下面我的appdelegate內的一個實例變量:目標C:AppDelegate中的NSString
distributedLCAAppDelegate.h:從distributedLCAAppDelegate.m
@class distributedLCAViewController;
@interface distributedLCAAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
distributedLCAViewController *viewController;
NSString *token;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet distributedLCAViewController *viewController;
@property (nonatomic, copy) NSString *token;
@end
部分:
@implementation distributedLCAAppDelegate
@synthesize window;
@synthesize viewController;
@synthesize token;
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
token = [NSString stringWithFormat:@"%@",deviceToken];
token = [token stringByReplacingOccurrencesOfString:@" " withString:@""];
token = [token substringWithRange:NSMakeRange(1, [token length]-2)];
}
我需要能夠在視圖控制器中使用這個令牌變量。目前,這是我有:
從內distributedLCAViewController.m部分:
- (IBAction)switchWasActivated:(id)sender
{
NSString *token2 = [[[distributedLCAAppDelegate alloc] token] autorelease];
}
然而,token2 = 「無效cfstringref」。
我最初嘗試聲明一個名爲getToken的公共方法,它只返回了標記。但在這種情況下,我也遇到了同樣的問題。
任何幫助,將不勝感激!
你確定'didRegisterForRemoteNotificationsWithDeviceToken:'被調用嗎? – jonkroll 2012-04-10 05:05:37