如果用户收到新的聊天消息或通过我已在活动供稿中实施的某些其他操作,我想向其发送推送通知。我收到的所有活动消息,如果用户不在应用程序内,我想复制并推送通知。
我已经在app delegate.swift
中实现了一些常规内容:
import UserNotifications
import Firebase
import FirebaseInstanceID
import FirebaseMessaging
// The callback to handle data message received via FCM for devices running iOS 10 or above.
func applicationReceivedRemoteMessage(_ remoteMessage: MessagingRemoteMessage) {
print(remoteMessage.appData)
}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
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 })
// For iOS 10 data message (sent via FCM
Messaging.messaging().delegate = self
} else {
let settings: UIUserNotificationSettings =
UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
application.registerUserNotificationSettings(settings)
}
application.registerForRemoteNotifications()
FirebaseApp.configure()
UITabBar.appearance().tintColor = UIColor.black
UIBarButtonItem.appearance().tintColor = .black
return true
}
这是我的活动供稿,用于收集网络中的所有活动。全部如果用户不在应用程序内,我希望将其作为推送通知发送给用户:
func updateView(report: ReportingModel) {
if report.type == "post" {
statusLabel.text = "hat einen neuen Post erstellt"
createTime(report: report)
guard let postId = report.objectId else { return }
PostApi.shared.observePost(withPostId: postId, completion: { (post) in
guard let postImageUrlSting = post.imageURL else { return }
guard let imageUrl = URL(string: postImageUrlSting) else { return }
self.postImageView.sd_setImage(with: imageUrl, completed: { (_, _, _, _) in
})
})
} else if report.type == "comment" {
statusLabel.text = "hat einen neuen Kommentar erstellt"
createTime(report: report)
guard let postId = report.objectId else { return }
PostApi.shared.observePost(withPostId: postId, completion: { (post) in
guard let postImageUrlSting = post.imageURL else { return }
guard let imageUrl = URL(string: postImageUrlSting) else { return }
self.postImageView.sd_setImage(with: imageUrl, completed: { (_, _, _, _) in
})
})
} else if report.type == "like" {
statusLabel.text = "hat deinen Beitrag geliked"
createTime(report: report)
guard let postId = report.objectId else { return }
PostApi.shared.observePost(withPostId: postId, completion: { (post) in
guard let postImageUrlSting = post.imageURL else { return }
guard let imageUrl = URL(string: postImageUrlSting) else { return }
self.postImageView.sd_setImage(with: imageUrl, completed: { (_, _, _, _) in
})
})
} else if report.type == "dislike" {
statusLabel.text = "hat deinen Beitrag gedisliked"
createTime(report: report)
guard let postId = report.objectId else { return }
PostApi.shared.observePost(withPostId: postId, completion: { (post) in
guard let postImageUrlSting = post.imageURL else { return }
guard let imageUrl = URL(string: postImageUrlSting) else { return }
self.postImageView.sd_setImage(with: imageUrl, completed: { (_, _, _, _) in
})
})
}
}
但是如何将活动供稿连接到我的推送通知? 我现在收到一些通过云消息手动发送的推送通知。
在此先感谢您的帮助!