Apple 推送通知:未收到设备令牌?
Apple Push Notifications: Not receiving device token?
在一个涉及推送通知的应用程序中,我可以很好地接收设备令牌,但我客户的设备没有收到设备令牌(因此导致无法接收推送通知)。我正在使用 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)];
}
在您的 AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
方法中 class
在一个涉及推送通知的应用程序中,我可以很好地接收设备令牌,但我客户的设备没有收到设备令牌(因此导致无法接收推送通知)。我正在使用 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)];
}
在您的 AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
方法中 class