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