I’m testing in Swift to ship notifications with Firebase and on the whole it is working. When i’ll ship a notification to 1 consumer, i want the gadget token of this consumer. I suppose this isn’t the identical because the UUID?
By the creation of the account i prefer to retailer this id within the db by including the id within the url (GET) within the webview web page. How am i able to do this? Is there an answer?
Here is the ViewController.swift code
import UIKit
import WebKit
class ViewController: UIViewController {
let webView=WKWebView()
override func viewDidLoad() {
tremendous.viewDidLoad()
view.addSubview(webView)
guard let url = URL(string: "**https://myurl.be/app.php?gadget=CODE**")else {
return
}
webView.load(URLRequest(url:url))
// Do any extra setup after loading the view.
}
override func viewDidLayoutSubviews() {
tremendous.viewDidLayoutSubviews()
webView.body = view.bounds
}
}
AppDelegate.swift
import UIKit
import FirebaseCore
import FirebaseMessaging
import UserNotifications
@essential
class AppDelegate: UIResponder, UIApplicationDelegate {
let gcmMessageIDKey = "gcm.Message_ID"
var deviceTokenString: String?
var testString = "take a look at"
func software(_ software: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Knowledge) {
deviceTokenString = deviceToken.scale back("", {$0 + String(format: "%02X", $1)})
print("===== deviceTokenString =====")
print(deviceTokenString ?? "nok")
}
func software(_ software: UIApplication, didFinishLaunchingWithOptions launchOptions:
[UIApplication.LaunchOptionsKey: Any]?) -> Bool {
FirebaseApp.configure()
// Push Notifications
if #accessible(iOS 10.0, *) {
UNUserNotificationCenter.present().delegate = self
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.present().requestAuthorization(
choices: authOptions,
completionHandler: { _, _ in }
)
} else {
let settings: UIUserNotificationSettings =
UIUserNotificationSettings(sorts: [.alert, .badge, .sound], classes: nil)
software.registerUserNotificationSettings(settings)
}
software.registerForRemoteNotifications()
Messaging.messaging().delegate = self
return true
}
func software(_ software: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, choices: UIScene.ConnectionOptions) -> UISceneConfiguration {
return UISceneConfiguration(identify: "Default Configuration", sessionRole: connectingSceneSession.function)
}
func software(_ software: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>)
}
}
extension AppDelegate: UNUserNotificationCenterDelegate {
func userNotificationCenter(_ middle: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions)
-> Void) {
let userInfo = notification.request.content material.userInfo
print(userInfo)
completionHandler([[.alert, .sound]])
}
func userNotificationCenter(_ middle: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void) {
let userInfo = response.notification.request.content material.userInfo
print(userInfo)
completionHandler()
}
func software(_ software: UIApplication,
didReceiveRemoteNotification userInfo: [AnyHashable: Any],
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult)
-> Void) {
if let messageID = userInfo[gcmMessageIDKey] {
print("Message ID: (messageID)")
}
print(userInfo)
completionHandler(UIBackgroundFetchResult.newData)
}
}
extension AppDelegate: MessagingDelegate {
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) {
print("Firebase registration token: (String(describing: fcmToken))")
let dataDict: [String: String] = ["token": fcmToken ?? ""]
NotificationCenter.default.publish(
identify: Notification.Identify("FCMToken"),
object: nil,
userInfo: dataDict
)
}
func software(_application:UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Knowledge){
print (deviceToken.map({String(format: "%02x", $0 )}).joined()) //optie1
print (deviceToken.scale back(""){ $0 + String (format: "%02.2hhx", $1)}) //optie2
print (deviceToken.scale back(""){ $0 + String (format: "%.2x", $1)}) //optie3
}
}
I hope to discover a answer.