我在 iPhone 6 和 6 Plus (iOS 8.2) 上的应用程序有一个非常奇怪的问题。我已经关注并阅读了我在网上找到的几乎所有内容(我认为!),但它仍然不起作用。我已经在 iPhone 4 (iOS 7.1)、4s (iOS 7.1)、5s (iOS 8.1) 和 iPad Mini (iOS 8.2) 上测试了该应用程序,它们都可以从应用程序接收推送通知。我的 XCode 版本是 6.2,iPhone 6 设备(iOS 8.2)被检测为不符合条件的设备。所以我什至不能直接从 XCode 运行应用程序。
我正在使用 php 脚本来推送通知。当应用程序首次在 iPhone 6 上运行时,它会显示一个弹出警报,要求获得推送通知权限。在设备的设置中,应用程序位于通知设置中。我尝试撤销 apns 证书并创建一个新证书,重新生成 .pem 文件,重置设备内容和设置,卸载并安装应用程序。这些都没有奏效,我已经把头发拔掉了。我什至为此询问了 Apple 技术支持,但他们的回答真的只是废话。我尝试从具有推送通知功能的应用商店下载应用。在某种程度上,该设备可以接收来自该应用程序的推送通知。那么,这里有什么我想念的吗?有人可以帮助我吗?
如建议的那样,这是我用于注册通知的代码。我从“application:didFinishLaunchingWithOptions:”内部调用了“registerForRemoteNotification”方法:
- (void)registerForRemoteNotification
{
if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)])
{
NSLog(@"system version >= 8.0");
UIUserNotificationType types = UIUserNotificationTypeSound | UIUserNotificationTypeBadge | UIUserNotificationTypeAlert;
UIUserNotificationSettings *notificationSettings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];
}
else {
NSLog(@"system version < 8.0");
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
}
}
#ifdef __IPHONE_8_0
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings {
NSLog(@"Registering for remote notification");
[application registerForRemoteNotifications];
}
#endif
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
NSLog(@"did register remote notification with device token");
NSString *newToken = [deviceToken description];
newToken = [newToken stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]];
newToken = [newToken stringByReplacingOccurrencesOfString:@" " withString:@""];
NSLog(@"Device token: %@",newToken);
DataManager *sharedData = [DataManager sharedInstance];
sharedData.deviceToken = newToken;
[self requestProfileWithDeviceToken:newToken];
}
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
NSLog(@"Failed to get device token, error: %@", error);
[self requestProfileWithDeviceToken:@""];
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
NSLog(@"Receive push notification: %@",userInfo);
[self processPushNotification:userInfo];
}
任何帮助将不胜感激。干杯。