ios - 如何在不使用 parse.com 创建 channel 的情况下向特定设备发送推送通知?

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

在我的 ios 应用程序中,我正在使用 Parse.com api 有两个 View Controller , View Controller 1 显示我 friend 的 fb 个人资料照片。 View controller 2 显示好友资料。现在我想向我拥有其 FB id 的选定 friend 发送推送通知。 我可以在不创建 channel 的情况下使用 fb id 定位 friend 吗?

我正在尝试下面的代码,

//View Controller 1

//Register current user after login

-(void)registerUserForPushNotification
{
PFUser *user = [PFUser currentUser];
PFInstallation *currentInstallation = [PFInstallation currentInstallation];
[currentInstallation setObject:user forKey:@"Owner"];
[[PFUser currentUser] setObject:CurrentUserFacebookId forKey:@"fbId"];
[currentInstallation saveInBackground];
}


//View controller 2
//Send Push notification to  friend
-(void)sendPushNotification
{

// get the PFUser object for current user
PFQuery *userQuery=[PFUser query];
[userQuery whereKey:@"fbId" equalTo:ClientFBId];//ClientFBId is my friend's FB id

// send push notification to the user
PFQuery *pushQuery = [PFInstallation query];
[pushQuery whereKey:@"Owner" matchesQuery:userQuery];
PFPush *push = [PFPush new];
[push setQuery: pushQuery];
NSString *message=[[CurrentUserName stringByAppendingString:@" "]stringByAppendingString:@"sent you ilu"];    
[push setData: @{ @"alert":message}]; 
[push sendPush: nil];
}

我已经搜索了文档。一切都好。它甚至在 parse.com 上显示我的推送通知。但它说“您将此推送通知发送给了 0 个收件人。”在 parse.com 的推送通知选项卡顶部。

猜猜有什么问题吗?

请注意:- 我不会向所有 friend 发送推送通知,而是一次只向一个 friend 发送。所以我想,我不必创建 channel 。

最佳答案

发现我问题中提到的每一步都是正确的。两个代码都没有问题。 我注意到我的应用程序没有在解析控制台上接收设备 token 。所以我认为我的证书可能存在问题。

重新生成配置了推送通知的证书并再次创建配置文件。

这让它起作用了。现在在解析控制台上接收设备 token 并获取推送通知。 这是 link一步一步的指导。 不要错过任何一个。希望对大家有帮助!!!

关于ios - 如何在不使用 parse.com 创建 channel 的情况下向特定设备发送推送通知?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17501937/

相关文章:

ios - AutoLayout 的规则间距

ios - 如何使用 eventKit 框架为特定日期设置提醒(警报)

java - 在 Android Studio 中关闭应用程序时推送通知无法正常工作

iphone - 检查用户是否使用phonegap 1.7在iPhone上启用了推送通知

swift - UNUserNotificationCenterDelegate willPresent 不适用于 OneSignal

ios - Apple 推送通知操作按钮

ios - 如何在 swift 2.x 中使用 "one IBAction for multiple buttons"上的按钮?

ios - 当我在那个 swift ios 上绘制时,ImageView 会改变坐标

ios - 新站推送和执行代码

ios - 信标是否像地理围栏一样工作并且具有相同的 20 个限制?