Answer the question
In order to leave comments, you need to log in
Why does IOS receive one push but two notifications are displayed?
Good afternoon.
I send a push notification from the backend part of the app to the iOS and Android app
.
Array ( [registration_ids] => Array ( [0] => test_token ) [notification] => Array ( [title] => Notification title [body] => Notification text [sound] => 1 [content_available] => 1 [ priority] => high [badge] => 4 [smallIcon] => small_logo [click_action] => .NoticeFullController ) [data] => Array ( [short_text] => Notification short text [selectNotice] => 123 [selectStatus] = > 4 ) [apns] => Array ( [headers] => Array ( [apns-priority] => 5 ) [payload] => Array ( [aps] => Array ( [category] => notice_push ) ) ) )
import UserNotifications
import Firebase
import FirebaseMessaging
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Use Firebase library to configure APIs
FirebaseApp.configure()
// Уведомления в фоне
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge], completionHandler: {didAllow, error in})
// Override point for customization after application launch.
return true
}
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void)
{
completionHandler([.alert, .badge, .sound])
}
func userNotificationCenter(center: UNUserNotificationCenter, willPresentNotification notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void)
{
//Handle the notification
completionHandler(
[UNNotificationPresentationOptions.alert,
UNNotificationPresentationOptions.sound,
UNNotificationPresentationOptions.badge])
}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
Messaging.messaging().apnsToken = deviceToken
}
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String) {
Messaging.messaging().subscribe(toTopic: "notice_push")
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) {
let content = UNMutableNotificationContent()
if let title = userInfo["title"]
{
content.title = title as! String
}
if let short_text = userInfo["short_text"]
{
content.body = short_text as! String
} else if let short_text = userInfo["body"]
{
content.body = short_text as! String
}
if let badge = userInfo["badge"]
{
UIApplication.shared.applicationIconBadgeNumber = badge as! Int
}
//category = ".NoticeFullController";
content.userInfo = userInfo
content.sound = .default()
content.threadIdentifier = "my-notice"
if #available(iOS 12.0, *) {
content.summaryArgument = "notification"
} else {
// Fallback on earlier versions
}
UNUserNotificationCenter.current().delegate = self
let trigger = UNTimeIntervalNotificationTrigger.init(timeInterval: 0.5, repeats: false)
let request = UNNotificationRequest(identifier:"notice", content: content, trigger: trigger)
UNUserNotificationCenter.current().add(request) { (error) in
if let getError = error {
print(getError.localizedDescription)
}
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question