我正在用PHP编写通用FCM功能,以便向Android和IOS设备发送远程通知。
在IOS中,我在前台收到通知,但当App在后台时,我没有收到任何通知。
我从网上尝试了几种方法,没有任何帮助。
请帮我正确设置服务器端
尝试1:
$feildAryVar = array(
'content_available' => true,
'registration_ids' => $FcmUidVar,
'data' => array("MsgKey"=>json_encode($msgToSendVar)),
'notification' => array(
"title"=>"Fcm TtlMsg",
"body"=>"Fcm Dtl Msg",
"content_available"=> true)
);
尝试2:
$feildAryVar = array(
'registration_ids' => $FcmUidVar,
'data' => array("MsgKey"=>json_encode($msgToSendVar)),
'notification' => array(
"title"=>"Fcm Title Msg",
"body"=>"Fcm Detail Msg",
"content_available"=> true)
);
Ios App Deligate:
func application(appPsgVar: UIApplication,
didReceiveRemoteNotification userInfo: [NSObject : AnyObject])
{
FIRMessaging.messaging().appDidReceiveMessage(userInfo)
}
func application(AppPsgVar: UIApplication,
didReceiveRemoteNotification userInfo: [NSObject : AnyObject],
fetchCompletionHandler handler: (UIBackgroundFetchResult) -> Void)
{
handler(UIBackgroundFetchResult.NewData)
FIRMessaging.messaging().appDidReceiveMessage(userInfo)
}
@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
}
func applicationReceivedRemoteMessage(remoteMessage: FIRMessagingRemoteMessage)
{
let fcmNfnVar = remoteMessage.appData
print("Received Notification : \(fcmNfnVar)")
}