在涉及推送通知的应用程序中,我可以正常接收设备令牌,但是我的客户端的设备无法接收设备令牌(因此导致无法接收推送通知)。我正在使用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
尝试以下代码
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)];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
AppDelegate类中的方法内
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句