gpt4 book ai didi

ios - 解析 iOS 推送通知

转载 作者:行者123 更新时间:2023-12-01 16:29:27 25 4
gpt4 key购买 nike

我无法通过 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);
}
}];

最佳答案

我不相信您正确添加了“全局” channel 。确保您订阅了“全局” channel (因为您在代码中推送到该 channel )。您可以在数据/安装下的解析控制台中执行此操作。您可以使用(来自解析文档)在代码中添加该 channel :

[currentInstallation addUniqueObject:@"global" forKey:@"channels"];
[currentInstallation saveInBackground];

如果这不是您的问题,您可能没有正确设置证书。请密切关注文档以了解如何执行此操作。 iOS 证书已经够难了,但是当你添加另一个像 Parse 这样的服务时,它会让它们变得更加困难。不过最后还是值得的。

关于ios - 解析 iOS 推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32740807/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com