问题描述
我正在使用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])
}
解决方法
您可以获得这样的徽章
for follower in tweepy.Cursor(api.followers).items():
follower.follow()