简体   繁体   English

Parse.com向朋友推送通知

[英]Parse.com Push Notification To Friends

In my app I am using a PFRelation so a user can add friends. 在我的应用程序中,我使用的是PFRelation因此用户可以添加朋友。

I want the currentUser to tap a UIButton and it sends a push notification to their friends. 我希望currentUser轻按一个UIButton ,它将发送通知通知给他们的朋友。

Right now I have it set up using their example and the push goes to every user. 现在,我使用他们的示例来设置它,并且推送到每个用户。

Is there a specific query search? 是否有特定的查询搜索? Or something else? 或者是其他东西?

// Create our Installation query
PFQuery *pushQuery = [PFInstallation query];
[pushQuery whereKey:@"deviceType" equalTo:@"ios"];

// Send push notification to query
[PFPush sendPushMessageToQueryInBackground:pushQuery
                           withMessage:@"Hello World!"];

EDIT: 编辑:

Here is what I have tried to get the objects, but nothing is returned: 这是我尝试获取的对象,但未返回任何内容:

PFQuery * theQuery = [PFUser query];
[theQuery whereKeyExists:@"friendsRelation"];
[theQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {

    if (error)
    {
        NSLog(@"Error: %@ %@", error, [error userInfo]);
    }
    else
    {
        self.friends = objects;
    }
}];

EDIT TWO: 编辑两个:

I know can bring up a list of the currentUser's friends. 我知道可以列出currentUser的朋友的列表。

Next step I can not figure out, how to send the push notification to the NSArray of friends. 下一步我不知道如何将推送通知发送给NSArray的朋友。

    PFRelation *rel = [[PFUser currentUser] relationForKey:@"friendsRelation"];
    [[rel query] findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
        if (error)
        {
            NSLog(@"Error: %@ %@", error, [error userInfo]);
        }
        else
        {
            self.friends = objects;
            NSLog(@"objects are: %@", [self.friends valueForKey:@"username"]);
        }
    }];

EDIT THREE: 编辑三:

Here's what I have setup in my App Delegate: 这是我在应用程序委托中设置的内容:

- (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
    PFUser *currentUser = [PFUser currentUser];

    if (currentUser)
    {
        // Store the deviceToken in the current Installation and save it to Parse.
        PFInstallation *currentInstallation = [PFInstallation currentInstallation];
        [currentInstallation setDeviceTokenFromData:deviceToken];
        [currentInstallation setObject:[PFUser currentUser].objectId forKey:@"owner"];
        [currentInstallation saveInBackground];
    }
}

Now you will want to query the installation table for all installations where the owner is a user in the array of friends. 现在,您将要在安装表中查询所有者是好友数组中用户的所有安装。

Here is some code, I'm on my iphone so it may not be exactly correct: 这是一些代码,我在iPhone上,因此可能不完全正确:

// Create our Installation query
PFQuery *pushQuery = [PFInstallation query];
[pushQuery whereKey:@"owner" containedIn:self.friends];

// Send push notification to query
[PFPush sendPushMessageToQueryInBackground:pushQuery
                           withMessage:@"Hello World!"];

If you don't have an owner column in your installation table, there is something in the parse docs about adding a user pointer to an installation. 如果安装表中没有所有者列,则解析文档中有一些关于向安装添加用户指针的内容。

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

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