我正在尝试让我的应用程序在Xcode 8.0中运行,并且遇到了错误.我知道这个代码在以前版本的swift中运行良好,但我假设在新版本中更改了代码.这是我正在尝试运行的代码:
let settings = UIUserNotificationSettings(forTypes: [.Sound, .Alert, .Badge], categories: nil)
UIApplication.sharedApplication().registerUserNotificationSettings(settings)
UIApplication.shared().registerForRemoteNotifications()
Run Code Online (Sandbox Code Playgroud)
我得到的错误是"参数标签"(forTypes:,categories :)'与任何可用的重载都不匹配"
是否有一个不同的命令,我可以尝试使其工作?
我正在制作一个应用程序,我想在其中实现apple推送通知服务.我按照本教程中给出的分步说明进行操作.
但仍然没有调用这些方法.我不知道造成这个问题的原因.谁能帮我?
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
//NSString * token = [[NSString alloc] initWithData:deviceTokenencoding:NSUTF8StringEncoding];
NSString *str = [NSString stringWithFormat:@"Device Token=%@",deviceToken];
NSLog(@"Device Token:%@",str);
//NSLog(@"Device token is called");
//const void *devTokenBytes = [deviceToken bytes];
//NSLog(@"Device Token");
}
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)err {
NSString *str = [NSString stringWithFormat: @"Error: %@", err];
NSLog(@"Error:%@",str);
}
Run Code Online (Sandbox Code Playgroud) 我需要设备令牌才能在我的应用中实现推送通知.
我怎么能获得设备令牌,因为didRegisterForRemoteNotificationsWithDeviceToken方法在iOS 8上不起作用.我在app delegate中尝试了这个代码,但它没有给我设备令牌.
[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
[[UIApplication sharedApplication] registerForRemoteNotifications];
Run Code Online (Sandbox Code Playgroud) 首先,我在iPhone 6 Plus/iOS 8.1上,我已经在这里尝试了一切:为什么没有调用RegisterForRemoteNotificationsWithDeviceToken
仍然无济于事.总结一下:
在application:didFinishLaunchingWithOptions:我打电话:
if([application respondsToSelector:@selector(registerUserNotificationSettings:)]){
//iOS 8+
[application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
}else{
//pre-iOS 8
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
}
Run Code Online (Sandbox Code Playgroud)
在application:didRegisterUserNotificationSettings:我打电话:
[application registerForRemoteNotifications];
Run Code Online (Sandbox Code Playgroud)
我用断点检查了它,它被调用了.我还实现了两种方法:
application:didRegisterForRemoteNotificationsWithDeviceToken:
和
application:didFailToRegisterForRemoteNotificationsWithError:
但是,它们都没有被称为.不是错误,没有.控制台也没有错误.(我今天早些时候遇到了有关权利的问题,但创建了新的证书/配置文件解决了这个问题)
可能是什么问题?
更新:这是一些东西.在application:didRegisterUserNotificationSettings:我检查的通知设置,这里是我得到了什么:
(lldb) po notificationSettings
<UIUserNotificationSettings: 0x170031cc0; types: (none);>
Run Code Online (Sandbox Code Playgroud)
更新2:我再次检查了通知,发现现在我的应用程序被添加到设置中的通知中,它已启用,具有权限.但是,仍然没有调用处理程序.类型是没有的.我99%肯定这与问题有关.
更新3:我已经在另一台设备上测试过(iPod touch,iOS 8.1),我没有遇到任何问题.它立即application:didRegisterForRemoteNotificationsWithDeviceToken:使用其令牌调用该方法.问题是我的iPhone特有的.
xcode push-notification apple-push-notifications ios provisioning-profile
我已经在我的应用程序中实现了apns,它一直工作到昨天没有任何问题.今天它突然停止工作,并且没有调用以下方法:
-(void) application:(UIApplication) applicaton didRegisterForRemoteNotificationWithDeviceToken:(nonnull NSData *) deviceToken;
Run Code Online (Sandbox Code Playgroud)
我没有找到任何正当理由.我的iOS版本是9.3.2;
在设备日志中,我看到以下错误消息:
无法验证courier.sandbox.push.apple.com的证书链
我出厂重置设备,但它没有工作.
有趣的是,apns可以在我的其他设备上使用相同的iOS版本.
更有趣的是,在同一台设备上,我的另一个测试推送应用程序(相同的代码复制和粘贴)工作正常.
有人有任何想法解决这个问题吗?
提前致谢.