使用Parse.com发送静默推送通知

时间:2014-11-17 08:58:35

标签: ios parse-platform push-notification silent

我想知道是否有一种使用parse.com服务向用户发送静默推送通知的好方法。

通过"无声",我的意思是如果用户在应用程序中没有实际通知(如果用户不在应用程序中,我会发送正常的通知),没有"警告"消息,没什么。只是一个离散的函数调用。

我需要这个来在用户进入应用程序时执行一些代码。

我已经在我可以使用云代码的文档中读到了

  1. 最好吗?
  2. 我该怎么办?没有其他解释。
  3. 在没有用户注意的情况下,是否有另一种更有效/移动友好的方式来远程调用功能。
  4. 我应该使用obj-C代码吗?云代码?你能提供一个小例子吗? (我真的只需要在我的代码中默默地调用"刷新"函数,没什么好看的)

    非常感谢:)

3 个答案:

答案 0 :(得分:7)

我为我做这件事并且有效。

第一: 在您的项目功能中,转到"背景"并检查"远程通知"

第二: 在您的appdelegate中,请务必使用此方法处理后台(静音)推送。

-(void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler{

//i handle the silent push here with a test on the userinfo's param.
// if content-available = 1 do some stuff
// else 
    // [PFPush handlePush:userInfo];

}

最后: 当您在推送中设置数据时,您必须添加" content-available" = 1并删除声音

 NSDictionary *data = [NSDictionary dictionaryWithObjectsAndKeys:
                          temp, @"alert",
                          @"Increment", @"badge",
                          @"", @"sound",
                          @1, @"content-available",
                          nil];

NSDictionary *data =@{
      @"badge": @"Increment",
      @"alert": temp,
      @"sound": @"",
      @"content-available" :@1
      };

答案 1 :(得分:0)

您可以将云代码功能用于此类场景。 我对解析云功能的了解不多。这是您所期望的示例云代码。

这是您定义云功能的方式

Parse.Cloud.define("SomeFunction", function(request, response) {
//Write queries as you need
});

Then call this cloud function as follows
[PFCloud callFunctionInBackground:@"SomeFunction" withParameters:parameters block:^(id object, NSError *error) {
//Add this function in some method & call the method wherever you needed, suppose if you need to update your app which has SwipingSideMenu like functionalities, for each time you click on the menu or side button call this cloud function. Thats it.
}];

答案 2 :(得分:0)

您也可以参考https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html

  

aps词典还可以包含content-available属性。值为1的content-available属性允许远程通知充当“静默”通知。当无声通知到达时,iOS会在后台唤醒您的应用程序,以便您可以从服务器获取新数据或进行后台信息处理。用户不会被告知由静默通知产生的新信息或更改信息,但他们可以在下次打开您的应用时找到相关信息。