[英]How to get iphone device token for push notification?
I am trying to use Remote Push Notification in my app, and I was trying to have this test out within my app, but i couldn't reset the alert popup after i tap on "Allow" at the very beginning. 我正在尝试在我的应用程序中使用远程推送通知,我试图在我的应用程序中进行此测试,但在我开始点击“允许”后我无法重置警报弹出窗口。
so my question is: 所以我的问题是:
Do i still get the device token even when the user tap "Don't Allow" in the alert popup? 即使用户在警告弹出窗口中点击“不允许”,我仍然可以获得设备令牌吗?
use appDelegate method 使用appDelegate方法
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
self.mDeviceToken = deviceToken;
//Removing the brackets from the device token
NSString *tokenString = [[deviceToken description] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]];
NSLog(@"Push Notification tokenstring is %@",tokenString);
}
and in case error 以防万一
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
NSString* s=[[NSString alloc] initWithFormat:@"%@",error];
UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Error" message:s delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
[s release];
// lert because your device will not show log
}
Use following delegates method... 使用以下代理方法...
-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{
NSLog(@">>%@",deviceToken);// this will give you token
}
-(void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error{
NSLog(@">>%@",error); // this will gave you error msg with description.
}
Hope, this will help you.. 希望这个能对您有所帮助..
-(void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
{
NSLog(@"My token is: %@", deviceToken);
}
In this way you get iPhone device token 通过这种方式,您可以获得iPhone设备令牌
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.