FCM push notification background issue

I have set all capabilities for background even i get notification when app is in foreground mode and also in background from fcm console.But when i send notification from my server it do not work for background.This is my php code

$msg = array

(

'message' => $post_sms,

'date' => $date,

'value' => '1',

'usrkey' => $admin_id,

'msgcount' => $countid

);

$fields = array(

'registration_ids' => array($sid),

'priority' => 'high',

'data' => $msg

);

$headers = array(

'Authorization: key=' . $key,

'Content-Type: application/json'

);


i also have tried this one


$msg['aps'] = array(

'alert' => array(

'title' =>$post_sms,

'body' => $countid,

'usrkey' => $admin_id,

),

'sound' => 'default'

);

But still not working for background.Please let me known any solution regarding this.

To run background it's not using the push class. Background remote notification is handled by the UIApplication sharedinstance.

these lines need to be in the code:


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

[[UIApplication sharedApplication] registerForRemoteNotifications];



in ios10 and above you need this handler

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


if you have this handler:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo


it will not be going through. Not sure if you need the delegate set to your AppDelegate or not for this. i think that's a given though.

Hope this helps.


I just mention the first lines to make sure everything is there.

FCM push notification background issue
 
 
Q