0

소셜 네트워크 앱을 개발 중이며 사용자는 함께 팔로우/언 폴링 할 수 있습니다. A와 유사한 인스 타 그램을 따라 X가있을 때 firebase 클라우드 기능으로부터 어떻게 알림을받을 수 있습니까?FCM 기능 - 알림 수신

내하는 index.js는 중포 기지

my index.js codes

내 프로젝트 AppDelegate에에 배포 : 확인 등의

import UIKit 
import Firebase 
import UserNotifications 

    @UIApplicationMain 
class AppDelegate: UIResponder, 
UIApplicationDelegate,UNUserNotificationCenterDelegate, 
MessagingDelegate { 
func messaging(_ messaging: Messaging, didRefreshRegistrationToken 
fcmToken: String) { 
    print("Firebase registration token: \(fcmToken)") 
} 


var window: UIWindow? 


func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 

    UITabBar.appearance().tintColor = .white 


    if #available(iOS 10.0, *) { 
     // For iOS 10 display notification (sent via APNS) 
     UNUserNotificationCenter.current().delegate = self 

     let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound] 
     UNUserNotificationCenter.current().requestAuthorization(
      options: authOptions, 
      completionHandler: {_, _ in }) 
    } else { 
     let settings: UIUserNotificationSettings = 
      UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil) 
     application.registerUserNotificationSettings(settings) 
    } 

    application.registerForRemoteNotifications() 


    FirebaseApp.configure() 

    let token = Messaging.messaging().fcmToken 
    print("FCM token: \(token ?? "")") 

    return true 

} 




func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { 
    var token = "" 
    for i in 0..<deviceToken.count { 
     token = token + String(format: "%02.2hhx", arguments: [deviceToken[i]]) 
    } 
    print("Registration succeeded! Token: ", token) 
} 

func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) { 
    print("Registration failed!") 
} 





func application(_ application: UIApplication,didReceiveRemoteNotification notification: [AnyHashable:Any],fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) { 
    if Auth.auth().canHandleNotification(notification){ 
     completionHandler(UIBackgroundFetchResult.noData) 
    } 

    // This notification is not auth related, developer should handle it. 
} 

func applicationDidBecomeActive(_ application: UIApplication) { 

    //YFVolumeView.current.updateActiveState() 
} 


// Firebase notification received 
@available(iOS 10.0, *) 
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (_ options: UNNotificationPresentationOptions) -> Void) { 

    // custom code to handle push while app is in the foreground 
    print("Handle push from foreground\(notification.request.content.userInfo)") 

    let dict = notification.request.content.userInfo["aps"] as! NSDictionary 
    let d : [String : Any] = dict["alert"] as! [String : Any] 
    let body : String = d["body"] as! String 
    let title : String = d["title"] as! String 
    print("Title:\(title) + body:\(body)") 
    self.showAlertAppDelegate(title: title,message:body,buttonTitle:"ok",window:self.window!) 

} 

@available(iOS 10.0, *) 
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping() -> Void) { 
    // if you set a member variable in didReceiveRemoteNotification, you will know if this is from closed or background 
    print("Handle push from background or closed\(response.notification.request.content.userInfo)") 
} 

func showAlertAppDelegate(title: String,message : String,buttonTitle: String,window: UIWindow){ 
    let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.alert) 
    alert.addAction(UIAlertAction(title: buttonTitle, style: UIAlertActionStyle.default, handler: nil)) 
    window.rootViewController?.present(alert, animated: false, completion: nil) 
} 
// Firebase ended here 

} 

Firebase Cloud Functions

모든하지만 X가 다음에 할 때, 내 장치에서 돈 ' 알림을받지 못한다!

답변

0

난 당신이 잘못된 토큰을 사용하고 있는지 생각

let fcmToken = Messaging.messaging().fcmToken

let apnsToken = Messaging.messaging().apnsToken

FMC 사용 sprecial의 토큰이 didRegisterForRemoteNotificationsWithDeviceToken에서 IOS 토큰을 받았을 때

,받은 것 FCM 토큰

fcmToken과 FCM을 사용하면 장치에 통지

희망이 도움

+0

[중포 기지/메시징] [I-FCM001000] FIRMessaging 프록시가 활성화 원격 알림, 원격 알림 수신 핸들러를 스위 즐링 (swizzle)합니다. Info.plist에 "FirebaseAppDelegateProxyEnabled"를 추가하고 그것을 NO로 설정하십시오 APN 토큰 검색 : 32 바이트 Firebase 등록 토큰 : cwUSCeYLTdxxxxxxxxxxxxxxxx –