Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending silent push notifications using Parse.com

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

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

I need this to perform some code while the user is in the app.

I've read in the doc that I can use cloudcode but

  1. Is it best?
  2. How can i do it? there is no other explanation about it.
  3. Is there another way that is more efficient/mobile friendly to call a function remotely without the user noticing.

Should I use obj-C code? cloud code? Can you provide a small example ? (I really just need to call a "refresh" function in my code silently, nothing fancy)

Thanks a lot :)

like image 902
Gil Sand Avatar asked May 18 '26 04:05

Gil Sand


1 Answers

I do this on for me and it works .

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

Second : In your appdelegate be sure to have this method which handle the 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's param.
// if content-available = 1 do some stuff
// else 
    // [PFPush handlePush:userInfo];

}

and finally : When you set the data in your push you have to 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
      };
like image 114
Smiless Avatar answered May 20 '26 16:05

Smiless



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!