在涉及推送通知的应用中,我接收设备令牌就好了,但我客户端的设备没有收到设备令牌(因此导致无法接收推送通知)。我正在使用Parse进行推送通知。这就是我AppDelegate
中的内容:
-(void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)newDeviceToken {
// Store the deviceToken in the current installation and save it to Parse.
PFInstallation *currentInstallation = [PFInstallation currentInstallation];
[currentInstallation setDeviceTokenFromData:newDeviceToken];
PFACL *objectACL = [[PFACL alloc] init];
[objectACL setPublicReadAccess:YES];
[objectACL setPublicWriteAccess:YES];
[currentInstallation saveInBackground];
}
-(void) application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
NSString *errorString = [NSString stringWithFormat:@"%@", error];
UIAlertView *errorAlertView = [[UIAlertView alloc] initWithTitle:@"Error" message:errorString delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[errorAlertView show];
}
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings {
[application registerForRemoteNotifications];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[Parse setApplicationId:PARSE_APPLICATION_ID
clientKey:PARSE_CUSTOMER_KEY];
[PFFacebookUtils initializeFacebook];
[self.window makeKeyAndVisible];
// create the Login controller instance:
[application registerForRemoteNotificationTypes:
UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeSound];
}
客户端未收到任何表示未通过APN注册的UIAlert,因此无法调用didFailToRegisterForRemoteNotificationsWithError
。我已经尝试从我的解析服务器中删除所有安装,删除了应用程序&根据Apple技术说明TN2265的指导原则重新安装。该应用程序不会在首次启动时提示客户端授权推送通知。也没有出现在通知中心(这是令人困惑的,因为didRegisterUserNotificationSettings:
也存在)。但这一切在我的iPad,iPhone 5S,iPod 5,iPhone 4s上运行良好。任何想法可能导致该设备在应用程序中设备变量行为?这是sc客户端发给我的。notificationCenterScreenShot
答案 0 :(得分:2)
尝试以下代码
if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)])
{
[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
else
{
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
(UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)];
}
在AppDelegate类的- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
方法中