我有一个 NSString 作为我的 appdelegate 中的实例变量,如下所示:
分布式LCAAppDelegate.h:
@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
来自distributedLCAAppDelegate.m 的部分:
@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 的公共方法,它只返回令牌。但在那种情况下我也遇到了同样的问题。
任何帮助,将不胜感激!