0
私はソーシャルネットワークアプリを開発しており、ユーザーは一緒にフォロー/フォローできます。どのようにXがAのようなinstagramをたどったとき、firebaseのクラウド機能から通知を受け取ることができますか?FCM機能 - お知らせを受信
私のindex.jsはfirebase
マイプロジェクトAppdelegate上で展開します。okのような
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
}
は
すべてが、Xが続いたときに、私のデバイス上のドン」通知を受け取りません!
[Firebase /メッセージング] [I-FCM001000] FIRMessagingプロキシが有効になってリモート通知は、リモート通知受信ハンドラをスウィズルします。 Info.plistに「FirebaseAppDelegateProxyEnabled」を追加し、それをNOに設定してください APNトークンを取得しました:32バイト Firebase登録トークン:cwUSCeYLTdxxxxxxxxxxxxxxxx –