苹果推送通知:不接收设备令牌? [英] Apple Push Notifications: Not receiving device token?
问题描述
在涉及推送通知的应用程序,我收到设备令牌就好了,但我的客户的设备不会接收设备令牌(从而造成未收到推送通知)。我使用的解析推送通知。这是我在我的的AppDelegate
:
In an app which involves push notifications, I am receiving device tokens just fine but the my client's device doesn't receive device token (hence causing failure to receive push notifications). I am using Parse for push notifications. This is what I have in my 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];
}
客户端没有收到任何注册UIAlert重新presenting衰竭APN因此,这意味着 didFailToRegisterForRemoteNotificationsWithError
不会被调用。我曾尝试去除我的解析服务器的所有安装,删除应用&放大器;再重新安装按照苹果公司的技术说明TN2265的指导方针。该应用程序不会提示在第一次发射及功放推送通知的授权客户端;没有出现在通知中心是(这是因为莫名其妙 didRegisterUserNotificationSettings:
是有太多)。但是,这一切都在我的iPad,iPhone 5S,iPod的5,iPhone 4S做工精细。任何想法可能会在应用程序会导致此设备与设备变量的行为呢?!这是SC客户发给我。的 notificationCenterScreenShot
Client doesn't receive any UIAlert representing failure of registration with APN so that means didFailToRegisterForRemoteNotificationsWithError
is not being called. I have tried removing all installations from my parse server, removing the app & reinstalling again as per guidelines of Apple technical note TN2265. The application doesn't prompt the client for authorization of push notifications on first launch & doesn't appear in notification center either (Which is baffling because didRegisterUserNotificationSettings:
is there too). But all this is working fine on my iPad, iPhone 5S, iPod 5, iPhone 4s. Any ideas what Might be causing this device to device variable behavior in the app?!This is the sc client sent me.notificationCenterScreenShot
推荐答案
尝试以下code
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)应用:(*的UIApplication)的应用didFinishLaunchingWithOptions:(NSDictionary的*)launchOptions
方法在你的AppDelegate类
within - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
method in your AppDelegate class
这篇关于苹果推送通知:不接收设备令牌?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!