您的位置:首页 > 移动开发 > IOS开发

iOS 获取token笔记

2014-05-07 12:35 489 查看
//注册
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary
*)launchOptions
{

    self.window = [[UIWindow
alloc] initWithFrame:[[UIScreen
mainScreen] bounds]];

    // Override point for customization after application launch.

    

    

    [[UIApplication
sharedApplication] registerForRemoteNotificationTypes:

     UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert];

    

    self.indexVC = [[IndexViewController
alloc]
init];

    self.window.rootViewController =
self.indexVC;

    self.window.backgroundColor = [UIColor
whiteColor];

    [self.window
makeKeyAndVisible];

    return
YES;
}

//协议

-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData
*)deviceToken
{

    NSLog(@"deviceToken -- >> %@",deviceToken);
   
NSString *pushToken = [[[[deviceToken
description]

                             stringByReplacingOccurrencesOfString:@"<"
withString:@""]

                            stringByReplacingOccurrencesOfString:@">"
withString:@""]

                           stringByReplacingOccurrencesOfString:@" "
withString:@""];

    

    [[NSUserDefaults
standardUserDefaults] setObject:pushToken
forKey:@"Devicetoken"];

    [[NSUserDefaults
standardUserDefaults] synchronize];
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: