gpt4 book ai didi

ios - 解析推送通知 : User to User

转载 作者:行者123 更新时间:2023-11-29 02:13:14 28 4
gpt4 key购买 nike

您好,我正在制作一个使用互联网发送消息的消息传递应用程序。我需要从用户 a 向用户 b 发出通知。

我使用这段代码:

 if (toUser!= nil){
parseMessage[@"toUser"]=toUser;


//PFPush *push = [[PFPush alloc] init];
// [push setQuery://whatshouldiputhere?];
// [push setMessage:[NSString stringWithFormat: @"New Message from %@!", [PFUser currentUser].username]];
// [push sendPushInBackground];

}

此代码在发送消息时执行。这是行不通的。我究竟做错了什么?你能帮帮我吗?

感谢您的帮助。

最佳答案

从用户向用户发送推送通知与使用 channel 非常相似,首先您必须进行查询以找到用户,然后将该查询传递到推送通知中。

例如:

用户 A 向用户 B 发送了一条消息,您必须在后端进行查询才能找到用户 B。您可以通过多种方式使用 channel 、数组等,但对于本示例,我将使用 objectId:

-(void)sendPushNotificationToUserBWithObjectId:(NSString *)objectId {

// Build a query that matches user B's objectId (note you would have to save User B's objectId or retrieve it from a different query
PFQuery *subQuery = [PFUser query];
[subQuery whereKey:@"objectId" equalTo:objectId];

// Build the actual push notification from targeted query
PFQuery *finalQuery = [PFInstallation query];
// only return Installations that belong to a User that matches the subQuery & 'toUser' is objectId
[finalQuery whereKey:toUser matchesQuery:innerQuery];

// Send the notification.
PFPush *push = [[PFPush alloc] init];
[push setQuery:finalQuery];
[push setMessage:@"Message"];
[push sendPushInBackground];
}

你可以随时这样调用它:

[self sendPushNotificationToUserBWithObjectId:@"xVyWO18"]; 

其中@"xVyWO18"是用户B的objectId

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

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