I am implementing FCM push Notification.
I get notification when App is in foreground.
But I do not get Notification in the background.
In server end I have set content-available => true
On iOS 10, should I implement any other method or where do I get background notification?
@available(iOS 10.0, *)
func userNotificationCenter(center: UNUserNotificationCenter, willPresentNotification notification: UNNotification, withCompletionHandler completionHandler: (UNNotificationPresentationOptions) -> Void)
{
print("userNotificationCenter : Forground")
completionHandler([.Alert,.Sound,.Badge])
}
@available(iOS 10.0, *)
func userNotificationCenter(center: UNUserNotificationCenter, didReceiveNotificationResponse response: UNNotificationResponse, withCompletionHandler completionHandler: () -> Void)
{
//Code Todo After User presess notification
}
PHP Server Payload Code :
$payloadFeild = array(
'registration_ids' => $gotoFcmUidVar,
'data' => array('MsgKey'=>json_encode($fcmMsgVar)),
'content_available' => true,
'priority' => 'high'
);
I finally got this fixed after struggle 2 months by adding 2 things :
This is missing in all documentation and is to help all whom I wish not to struggle like me
|*| Try 1) : For Ios 10 background notification, Add following deligate method in AppDeligate :
func application(application: UIApplication, didRegisterUserNotificationSettings notificationSettings: UIUserNotificationSettings)
{
application.registerForRemoteNotifications()
}
Got this solution from : https://codentrick.com/firebase-cloud-messaging-ios/
|*| Try 2) : If using Firebase : Set a value in "info.plist"
Property List View :
FirebaseAppDelegateProxyEnabled -> NO
Source Code View :
<key>FirebaseAppDelegateProxyEnabled</key>
<false/>
I Had only mentioned FirebaseAppDelegateProxyEnable. So be careful of spelling too.