【问题标题】:Can I send remote push notification to my app from multiple servers?我可以从多个服务器向我的应用程序发送远程推送通知吗?
【发布时间】:2015-01-20 16:45:45
【问题描述】:

我正在为承包商构建 iOS 和 Android 应用程序。 基本上它是一个客户端,应该显示来自服务器的通知列表。

承包商计划将此应用程序提供给他的多个客户公司。他将为每家公司提供服务器(专用于该客户端),移动应用程序将安装在任何设备上,对于每个客户端车队,司机只需输入客户端服务器的 IP。

我的问题是 - 我可以将 Parse(或任何其他远程推送聚合器)与单个应用程序一起使用,但让多个服务器向设备发送推送通知(这些不会“广播”推送到所有设备 - 它们的目的是特定设备)?

【问题讨论】:

    标签: parse-platform push-notification


    【解决方案1】:

    我不确定这种情况下的“服务器”是什么,但 Parse 应该能够处理你想要的。

    我会在 Parse 中创建标准的 UserInstallation 类,以及一个名为“company”(或“client”或其他)的自定义类。你可以为这个类添加你喜欢的任何字段,但对你来说重要的似乎是“IP地址”。

    您可以将InstallationUser 关联,将Usercompany 关联。数据结构如下:

    Installation -> (Pointer)User
    User -> (Pointer)company
    company -> (String)ipAddress
    

    然后,当您想为特定 IP 地址发送 PUSH 时,您可以执行以下操作:

    1. 查询与“IP 地址”匹配的company
    2. 查询所有 User 对象,这些对象将 #1 的结果作为其 company 属性。
    3. 查询所有Installation 对象,这些对象的User 对象位于#2 返回的数组中。
    4. 使用 #3 中的查询发送 PUSH。

    这是在 Objective-C 中实现的一种方法:

    - (void)sendPushMessage:(NSString *)message 
      toClientWithIpAddress:(NSString *)ipAddress {
        PFQuery *companyQuery = [PFQuery queryWithClassName:@"company"];
        [companyQuery whereKey:@"ipAddress" equalTo:ipAddress];
        [companyQuery getFirstObjectInBackgroundWithBlock:^(PFObject *company, NSError *error) {
            // Do real error handling
            PFQuery *userQuery = [PFUser query];
            [userQuery whereKey:@"company" equalTo:company];
            [userQuery findObjectsInBackgroundWithBlock:^(NSArray *users, NSError *error) {
                // Do real error handling
                PFQuery *installationQuery = [PFInstallation query];
                [installationQuery whereKey:@"user" containedIn:users];
                PFPush *push = [PFPush push];
                [push setQuery:installationQuery];
                [push setMessage:message];
                // You could also have a completion block for this, if desired
                [push sendPushInBackground];
            }
             ];
        }
         ];
    }
    

    警告:虽然我用 Objective-C 编写了代码,虽然 Parse 允许客户端推送,但建议您从云代码函数。

    【讨论】:

    • 谢谢!会试试这个。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-18
    • 1970-01-01
    • 2015-12-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多