사람들 모두 Firebase 및 IOS 알림을 통해 사람들이 겪고있는 몇 가지 문제점을 읽었지 만 누구나 동일한 문제가있는 것으로 보입니다. 포어 그라운드에서 파이어베이스 알림 (데이터 만) 수신 안 함
는 지금 내가 FOREGROUND 응용 프로그램의 상태를 말하는거야 :응용 프로그램은이 같은 exemple에 대한 매개 변수 알림이 이제까지 통지가 나타납니다
let notificationsParameters:[String:AnyObject] = [
"to": "iphoneID",
"content-available":true,
"priority":"high",
// "notification" : [
// "body" : "great match!",
// "title" : "Portugal vs. Denmark",
// "icon" : "myicon"
// ],
"data" : [
"Nick" : "Mario",
"Room" : "PortugalVSDenmark"
]
]
을하지만 난 통지 부분을 제거하면 앱은 아무 것도받지 못합니다. 모든 사람이 알림을 받아야하는 전경을 유지하는 경우에도 마찬가지입니다.
폐쇄/배경 및 콘텐츠 사용 가능 여부에 우선 순위를 추가했는데, 이는 내가 읽었을 때 내 문제를 해결하는 데 도움이되지만 그렇지 않습니다. 여기
당신은 관련 코드가 있습니다
APP 대리자를
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
GMSServices.provideAPIKey(Constants.GoogleMaps.APIKey)
FIRApp.configure()
/* NOTFICATIONS */
let notificationsType:UIUserNotificationType = [UIUserNotificationType.Alert, UIUserNotificationType.Badge, UIUserNotificationType.Sound]
let notificationSettings = UIUserNotificationSettings(forTypes: notificationsType, categories: nil)
application.registerForRemoteNotifications()
application.registerUserNotificationSettings(notificationSettings)
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(self.tokenRefreshNotification(_:)), name: kFIRInstanceIDTokenRefreshNotification, object: nil)
return true
}
내가 알고있는 것처럼
이 내가받을 suppouse 무엇이다 (APP 위임 IN) NOTIFICATIONS 통지 데이터
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject],
fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
// If you are receiving a notification message while your app is in the background,
// this callback will not be fired till the user taps on the notification launching the application.
// TODO: Handle data of notification
// Print message ID.
print("Message ID: \(userInfo["gcm.message_id"]!)")
// Print full message.
print("%@", userInfo)
}
func tokenRefreshNotification(notification:NSNotification) {
let refreshedToken = FIRInstanceID.instanceID().token()
print("InstanceID token: \(refreshedToken)")
connectToFCM()
}
func connectToFCM() {
FIRMessaging.messaging().connectWithCompletion { (error) in
if error != nil {
print("GMS ERROR: \(error)")
}
else {
print("Connected to GMS")
}
}
}
당신이 필요로 바로 알려 중포 기지 NOTIFICATIONS
func sendNotification() {
let notificationsParameters:[String:AnyObject] = [
"to": "iphoneID",
"content-available":true,
"priority":"high",
// "notification" : [
// "body" : "great match!",
// "title" : "Portugal vs. Denmark",
// "icon" : "myicon"
// ],
"data" : [
"Nick" : "Mario",
"Room" : "PortugalVSDenmark"
]
]
let URL = NSURL(string: "https://fcm.googleapis.com/fcm/send")!
let URLRequest = NSMutableURLRequest(URL: URL)
URLRequest.HTTPMethod = "POST"
URLRequest.setValue("key=\(Constants.Firebase.NotificationsKey)", forHTTPHeaderField: "Authorization")
URLRequest.setValue("application/json", forHTTPHeaderField: "Content-Type")
let encoding = Alamofire.ParameterEncoding.JSON
let encoded = encoding.encode(URLRequest, parameters: (notificationsParameters)).0
Alamofire.request(encoded)
}
더 이상의 정보에 6,
CALL!
let notificationsParameters:[String:AnyObject] = [
"to": "iphoneID",
"content-available":true,
"priority":"high",
"notification" : [
"sound" : " "
],
"data" : [
"Nick" : "Mario",
"Room" : "PortugalVSDenmark"
]
]
애플 리케이션이 살해 될 때 당신은 알림을 수신하지 않습니다하지만 당신은 단지 데이터를 수신 할 수있을 것입니다 : 나, 하나 개의 솔루션은 다음과 같이 통지 매개 변수를 설정하는 것과 동일한 문제를 가지고 사람들을 위해
가이 해결있어했다 ..? –