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

3
我想知道是否有一种好的方法可以使用parse.com服务向用户发送静默推送通知。所谓“静默”,是指如果用户在应用程序中,则不会实际通知(如果用户不在应用程序中,则会发送正常通知),没有“警报”消息,什么都没有,只是一个离散的函数调用。
我需要在用户使用应用程序时执行一些代码。
我在文档中读到我可以使用云代码,但是:
1.它是最好的吗? 2.我该如何做?没有其他解释。 3.有没有另一种更有效/移动友好的方式来远程调用函数而不让用户注意到。
我应该使用obj-C代码?云代码?您能提供一个小例子吗?(我真的只需要在我的代码中静默调用“刷新”功能,没有花哨的东西)
非常感谢:)
3个回答

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

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

0

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

aps 字典也可以包含 content-available 属性。content-available 属性值为 1 时,远程通知将作为“静默”通知处理。当静默通知到达时,iOS 将在后台唤醒您的应用程序,以便您可以从服务器获取新数据或进行后台信息处理。用户不会被告知由静默通知导致的新变更信息,但他们可以在下次打开您的应用时了解它。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接