简体   繁体   English

如何在不使用parse.com创建频道的情况下将推送通知发送到特定设备?

[英]how to send push notification to a specific device without creating channels using parse.com?

In my ios app, i am using Parse.com api there are two view controllers, view controller 1 presents my friends fb profile photos. 在我的ios应用程序中,我正在使用Parse.com api,其中有两个视图控制器,视图控制器1展示了我的朋友们的fb个人资料照片。 View controller 2 presents the Friends profile. 视图控制器2呈现“朋友”个人资料。 now i want to send push notification to my selected friend whose FB id i have. 现在,我想向我具有FB ID的所选朋友发送推送通知。 can i target a friend with fb id without creating channel? 我可以在不创建频道的情况下以fb ID定位朋友吗?

i am trying following code, 我正在尝试遵循代码,

//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];
}

i have searched the docs. 我已经搜索了文档。 everything is fine. 一切顺利。 it even shows my push notification on parse.com. 它甚至在parse.com上显示我的推送通知。 but it says "You sent this push notification to 0 recipients." 但显示“您已将此推送通知发送给0个收件人。” on top of the push notification tab on parse.com. 在parse.com上的“推送通知”选项卡上。

any guesses whats wrong? 任何猜测怎么了?

please note:- i am not sending push notification to all the friends but only one friend at a time. 请注意:-我不是向所有朋友发送推送通知,而是一次仅发送给一个朋友。 so i guess, i dont have to create a channel. 所以我想,我不必创建频道。

Found out every step mentioned in my question was correct. 发现我的问题中提到的每个步骤都是正确的。 neither code had issue. 这两个代码都没有问题。 I noted that my app was not receiving device tokens on parse console.So i thought may be there's an issue with my certificate. 我注意到我的应用未在解析控制台上接收设备令牌,因此我认为我的证书可能存在问题。

Regenerated the certificate with push notification configured and created provisioning profile again. 使用配置的推送通知重新生成证书,并再次创建配置文件。

That got it working. 这样就可以了。 Receiving device tokens on parse console now and getting push notifications. 现在在解析控制台上接收设备令牌并获取推送通知。 here's the link for step by step instructions. 这是逐步说明的链接 don't miss a single one.hope it helps you all !!! 不要错过任何一个。希望它对您有帮助!

Parse lets you send push messages through either channels, or direct to installations (devices). 通过Parse,您可以通过任一渠道发送推送消息,或直接发送到安装(设备)。

What's important to realise is that a single user may have multiple installations associated with them - for example, they might own an iPhone and an iPad. 重要的是要认识到一个用户可能有多个与之相关的安装-例如,他们可能拥有iPhone和iPad。 You will want to send the push message to both. 您将要向两者发送推送消息。

It is hard to tell from what you've posted what's going on, as you've merged two view controllers together. 将两个视图控制器合并到一起,很难从发布的内容中看出来。 I assume that in your second view controller user is the user you are trying to send the push notification to? 我假设您的第二个视图控制器user是您要向其发送推送通知的用户? How are you obtaining the PFUser object that represents the friend? 您如何获取代表朋友的PFUser对象? Maybe share that code and you might get some more help. 也许共享该代码,您可能会获得更多帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM