我正在使用 Parse.com 在我的 iOS 应用程序中发送推送通知。
但是当我执行以下代码来创建 PFInstallation
对象时,设备 token 字段为空。
- (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)newDeviceToken {
// Store the deviceToken in the current installation and save it to Parse.
NSLog(@"didRegisterForRemoteNotificationsWithDeviceToken");
PFInstallation *currentInstallation = [PFInstallation currentInstallation];
[currentInstallation setDeviceTokenFromData:newDeviceToken];
[currentInstallation saveInBackground];
}
didFinishLaunchingWithOptions
方法
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
[Parse setApplicationId:@"xhjhkk869698lhlljk554hl55khlkhl4ff99065" clientKey:@"spg1t6jad1ShK2lh5456khh6j7j4nmn1YD6J6rl8vt3"];
[PFAnalytics trackAppOpenedWithLaunchOptions:launchOptions];
[FBProfilePictureView class];
// Register for push notifications
[application registerForRemoteNotificationTypes:
UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeSound];
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
return YES;
我注意到 didRegisterForRemoteNotificationsWithDeviceToken
从未执行过。我交叉检查了我的证书和配置文件,并使用指定的 here 方法测试了它们(请参阅制作 PEM 文件)。证书和连接工作正常。我还检查了我的 wifi 是否阻止了推送通知,没有问题。
所以任何人都可以请建议我在这里做错了什么?
最佳答案
你实现了吗? - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
也许你有一些错误,在这个方法中你可以得到它的描述。
关于ios - didRegisterForRemoteNotificationsWithDeviceToken 未执行 - 推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17697141/