gpt4 book ai didi

ios - ios 9 未注册设备 token

转载 作者:行者123 更新时间:2023-11-29 01:19:45 24 4
gpt4 key购买 nike

我为 ios 实现了推送通知。但是设备 token 是为 ipad 获取的,ios v 8.3 但是当我在 iphone 6s plus v9.0 中安装应用程序时,设备 token 没有注册。我根据创建所有证书this reference但我在 ipad 中收到通知,但没有收到 iphone。那么问题是什么。我找不到。请帮助我

if(IS_OS_8_OR_LATER) {
//Right, that is the point
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIRemoteNotificationTypeBadge
|UIRemoteNotificationTypeSound
|UIRemoteNotificationTypeAlert) categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
}
else{
//register to receive notifications
UIRemoteNotificationType myTypes = UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound;
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:myTypes];
}


- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
[application registerForRemoteNotifications];
}

-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
NSString *token=[deviceToken description];
token=[token stringByReplacingOccurrencesOfString:@">" withString:@""];
token=[token stringByReplacingOccurrencesOfString:@"<" withString:@""];
token=[token stringByReplacingOccurrencesOfString:@" " withString:@""];
if (token != nil) {
[[NSUserDefaults standardUserDefaults] setObject:token forKey:@"DEVICE_TOKEN"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
NSLog(@"token-->%@",token);
}

-(void)registerDeviceToken
{
NSUserDefaults* errDefaults = [NSUserDefaults standardUserDefaults];
NSString *regerr = @"no valid 'aps-environment' entitlement string found for application";
if ([[errDefaults objectForKey:@"ErrDesc"] isEqual: regerr] || [errDefaults objectForKey:@"DEVICE_TOKEN"] == nil) {
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Device token not register." message:@"Please check in member center that you have valid provisioning profile for your app." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}
else{
NSUserDefaults* statusvalue = [NSUserDefaults standardUserDefaults];
NSString *status = [statusvalue objectForKey:@"status"];
NSLog(@"Status->%@",status);
if ([status isEqualToString: @"SUCCESS"])
{
NSLog(@"%@",@"No need to register!!!");
}
else
{
NSString *urlString=[NSString stringWithFormat:@"%@?email=&regid=%@&app_type=utnews_v1&mobile=%@",webAPIURL,[[NSUserDefaults standardUserDefaults] objectForKey:@"DEVICE_TOKEN"],[[NSUserDefaults standardUserDefaults] objectForKey:@"mobile_no"]];

NSURL *url=[NSURL URLWithString:urlString];
NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:url];
NSLog(@"url-->%@",request.URL);
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
if(error)
{
[[[UIAlertView alloc] initWithTitle:@"Error" message:error.localizedDescription delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil] show];
}
else if (data.length>0)
{
NSString *responseString=[[NSString alloc] initWithBytes:[data bytes] length:[data length] encoding:NSUTF8StringEncoding];
NSLog(@"Response string-->%@",responseString);
NSMutableDictionary *parsedObject = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
NSString *parsevalue = parsedObject[@"status"];

NSLog(@"%@",parsevalue);

NSUserDefaults* statusvalue = [NSUserDefaults standardUserDefaults];

// Store data in prefereances
[statusvalue setObject:parsevalue forKey:@"status"];

// Save to disk
[statusvalue synchronize];
// NSDictionary *jsonDict=[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
}
else
{
// [[[UIAlertView alloc] initWithTitle:@"Alert" message:@"No response from server.Please try again." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil] show];
}
}];
}
}
}

最佳答案

也许您应该在 if(IS_OS_8_OR_LATER) 语句中添加 [[UIApplication sharedApplication] registerForRemoteNotifications];。希望对你有帮助

关于ios - ios 9 未注册设备 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34760494/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com