1

앱이 종료 된 후 Firebase를 통해 HTTP 요청을 통해 푸시 알림을 iOS 기기로 보내는 데 문제가 있습니다. 앱이 포 그라운드에 있거나 백그라운드에서 활성 상태이면 모든 것이 예상대로 작동합니다. 하지만 앱을 죽이면 작동하지 않습니다. 앱이 죽으면 Firebase 콘솔을 통해 내 앱에 알림을 보낼 수 있으므로 사용하고있는 코드에 문제가있는 것으로 생각됩니다.앱이 종료 된 후 HTTP 요청을 사용하여 Firebase (FCM)를 통해 iOS 장치에 푸시 알림 보내기

이 푸시 알림을 보내는 내 코드입니다 :

private void SendPushNotification(string devicetoken, string header, string content, string pushdescription) 
    { 
     var textNotification = new 
     { 
      to = devicetoken, 
      notification = new 
      { 
       title = header, 
       text = content, 
       content_available = true, 
       sound = "enabled", 
       priority = "high", 
       id = pushdescription, 
      }, 
      project_id = "rrp-mobile", 
     }; 

     var senderId = "212579566459"; 
     var notificationJson = Newtonsoft.Json.JsonConvert.SerializeObject(textNotification); 
     using (var client = new WebClient()) 
     { 
      client.Encoding = Encoding.UTF8; 
      client.Headers[HttpRequestHeader.ContentType] = "application/json"; 
      client.Headers[HttpRequestHeader.Authorization] = "key=AIfrSyAtgsWCMH4s_bOyj-Us4CrdsifHv-GqElg"; 
      client.Headers["Sender"] = $"id={senderId}"; 
      client.Headers[HttpRequestHeader.ContentType] = "application/json"; 
      client.UploadString("https://fcm.googleapis.com/fcm/send", "POST", notificationJson); 
     } 
    } 

내가 여기서 뭔가를 잊고 건가요? 이것은 전경, 배경 및 앱이 종료 될 때 Android 기기에 푸시 알림을 전송하는 데 효과적이며 전경 및 배경의 iOS 기기에도 마찬가지였습니다.

유일한 문제는 앱을 종료 할 때 푸시 알림을 iOS 기기로 보내는 것입니다. 누구든지이 문제를 어떻게 해결할 것인가에 대한 아이디어가 있습니까?

답변

1

저는 실수를 저질렀습니다. 매우 간단했습니다. 나는 이것을 놓칠 쉬운 일이 될 수 있기 때문에 여기에 게시하고 있습니다.

var textNotification = new 
    { 
     to = devicetoken, 
     notification = new 
     { 
      title = header, 
      text = content, 
      content_available = true, 
      sound = "enabled", 
      **priority = "high",** 
      id = pushdescription, 
     }, 
     project_id = "rrp-mobile", 
    }; 

당신은 우선 순위 속성이이처럼 "통지"범위 외부에 정의되어 있는지 확인해야합니다

var textNotification = new 
    { 
     to = devicetoken, 
     **priority = "high",** 
     notification = new 
     { 
      title = header, 
      text = content, 
      content_available = true, 
      sound = "enabled", 
      id = pushdescription, 
     }, 
     project_id = "rrp-mobile", 
    }; 

이 앱이 살해 된 경우에는 푸시 알림도 제공 할 것입니다.

+2

이것은 실제로 일반적인 실수입니다. 메시지를 높은 우선 순위로 보내지 않으면 메시지가 삭제되거나 전달 될 가능성이 높습니다. http://stackoverflow.com/questions/37332415/cant-send-push-notifications-using-the-server-api/37550067#37550067을 참조하십시오. –

관련 문제