我无法通过Parse.com正确设置推送通知。我相信我的推送是因为它们通过Parse显示在我的推送日志中。但是,无论我的推送发送到哪里(应用程序或仪表板),"推送发送"总是显示0.我知道这可能是一项复杂的任务,所以任何帮助都会非常感激!以下是我的代码:
AppDelegate.m
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[application setStatusBarStyle:UIStatusBarStyleLightContent];
[self setupAppearance];
// Parse.com setup
[Parse setApplicationId:@"RgOpkkSfRoOFvealb8uUbdElx6e4VwqrNA0ObZLl"
clientKey:@"GsMpLwqknU9c8qfPY0AaWUZzd7lE38ZTQQliM9TH"];
[PFUser enableRevocableSessionInBackground];
// Parse Push notifications setup
UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert |
UIUserNotificationTypeBadge |
UIUserNotificationTypeSound);
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes
categories:nil];
[application registerUserNotificationSettings:settings];
[application registerForRemoteNotifications];
return YES;
}
- (void)setupAppearance {
UINavigationBar *navigationBarAppearance = [UINavigationBar appearance];
navigationBarAppearance.barTintColor = [UIColor colorWithRed:0/255.0 green:0/255.0 blue:100/255.0 alpha:1.0f];
navigationBarAppearance.tintColor = [UIColor whiteColor];
navigationBarAppearance.titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor whiteColor]};
}
// push notification
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
// Store the deviceToken in the current installation and save it to Parse.
PFInstallation *currentInstallation = [PFInstallation currentInstallation];
[currentInstallation setDeviceTokenFromData:deviceToken];
currentInstallation.channels = @[ @"global" ];
[currentInstallation saveInBackground];
// Associate the device with a user
PFInstallation *installation = [PFInstallation currentInstallation];
installation[@"user"] = [PFUser currentUser];
[installation saveInBackground];
}
// push notification
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
[PFPush handlePush:userInfo];
}
InboxTableViewController.m
viewDidLoad中
//push code
NSDictionary *data = @{
@"alert" : @"message!",
@"badge" : @"Increment"
};
PFPush *push = [[PFPush alloc] init];
[push setChannel:@"global"];
//[push setMessage:@"message!"];
[push setData:data];
[push sendPushInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (!error) {
NSLog(@"The push campaign has been created.");
} else if (error.code == kPFErrorPushMisconfigured) {
NSLog(@"Could not send push. Push is misconfigured: %@", error.description);
} else {
NSLog(@"Error sending push: %@", error.description);
}
}];
答案 0 :(得分:0)
我不相信你正在添加"全球"通道正确。确保您订阅了" global" channel(因为你在代码中推送到那个频道)。您可以在数据/安装下的解析控制台中执行此操作。您可以使用(从解析文档中)在代码中添加该通道:
[currentInstallation addUniqueObject:@"global" forKey:@"channels"];
[currentInstallation saveInBackground];
如果这不是您的问题,您可能没有正确设置证书。请仔细阅读文档以了解如何执行此操作。 iOS证书很难,但是当你添加像Parse这样的服务时,它会让它们变得更加困难。最后值得。