ios - didRegisterForRemoteNotificationsWithDeviceToken 未执行 - 推送通知

标签 ios objective-c push-notification apple-push-notifications parse-platform

我正在使用 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/

相关文章:

ios - 导航栏中不同 View Controller 的不同颜色

ios - Xamarin IOS 暂时更改按钮的颜色

ios - 不使用 MFMailComposeViewController 发送电子邮件

objective-c - userDefaults 中的值未填充 URL 查询字符串

java - 如何删除从移动设备清除应用程序数据后触发的通知

java - 使用 Java HTTP Post 到 Google Cloud Messaging(Android 推送通知)

ios - 在 Swift 中使用 commitEditingStyle 动态删除 UITable 部分

iphone - UIWebView 从 javascript 音频播放器拦截 "setting movie path:"

ios - 如何在 View 之间保持类活力?

firebase - 如何本地化 Firebase 云消息通知?