Sending silent push notifications with Parse.com

I was wondering if there is a way to send silent push notifications to users using parse.com services.

By silent, I mean no actual notification if the user is in the app (I would send a normal one if the user was outside the app), no warning message, nothing. Just a discrete function call.

I need this to execute some code while the user is in the application.

I read in the doc that I can use cloudcode, but

  • This is better?
  • How can i do this? there is no other explanation.
  • Is there any other way that is more efficient / mobile to call a function remotely without notifying the user.

Should I use obj-C code? cloud code? Can you give me a small example? (I really just need to call the function "update" in my code quietly, nothing fancy)

Many thanks:)

+3


source to share


3 answers


I do this for me and it works.

First: In your project options go to "background" and check for "remote notification"

Second: Make sure your appdelegate has this method that handles background (silent) push.

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

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

}

      



and finally: When you set the data in your click you must add "content-available" = 1 and remove the sound

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

      

or

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

      

+7


source


The cloud code feature can be used for such scenarios. I am not very good at cloud parsing functions. Here's a cloud code example of what you'd expect.

This is how you define a cloud function



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


source


Also you can refer to https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html

The aps dictionary can also contain a content-accessible property. A content-accessible property with a value of 1 allows the remote notification to act as a "silent" notification. When a silent notification arrives, iOS wakes up your app in the background so you can fetch new data from your server or do background processing. Users arent told about new or changed information that came as a result of the silent notification, but they might find out about it the next time they open your app.

0


source







All Articles