Swift中我的FCM通知中缺少徽章变量

时间:2020-11-09 06:14:42

标签: swift push-notification firebase-cloud-messaging apple-push-notifications badge

我正在使用FCM在应用程序中接收通知,但由于通知中似乎缺少变量,因此我无法在应用程序图标上显示徽章计数。我该如何添加呢?

以下是我遇到的错误

  [AnyHashable("icon"): logo.png, AnyHashable("user_id"): 3, AnyHashable("google.c.sender.id"): 938224596608, AnyHashable("aps"): {
alert =     {
    body = "You have new message! Check in the app.";
    title = Tutil;
};
sound = default;
}, AnyHashable("google.c.a.e"): 1, AnyHashable("body"): You have new message! Check in the app., AnyHashable("user_photo"): images/3.png, AnyHashable("type"): message, AnyHashable("gcm.message_id"): 1604897386664267, AnyHashable("title"): Tutil, AnyHashable("user_name"): Mali, AnyHashable("lessons"): []] 

下面是我的代码

    func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
    let userInfo = notification.request.content.userInfo
    
    print("%@", userInfo)
    // Print message ID.
    let content = notification.request.content
    
    let badgeCount = content.badge as! Int //<<i am getting my error here as variables may not be available
    
    incrementBadgeNumberBy(badgeNumberIncrement: badgeCount)
    

 
    completionHandler([.alert,.badge,.sound])
}

1 个答案:

答案 0 :(得分:0)

您可以获得这样的徽章

for follower in tweepy.Cursor(api.followers).items():
    follower.follow()