Я новый разработчик и настроил OneSignal с моим приложением для iOS, а моя база данных - Firebase, однако я изо всех сил пытаюсь найти, как отправить push -уведомления определенным пользователям, когда они получат новое следствие, может ли кто -нибудь помочь
Это коды: < /p>
static func follow(uid: String) async throws {
guard let currentUid = Auth.auth().currentUser?.uid else { return }
let userFollowingDoc = FirestoreConstants.FollowingCollection.document(currentUid).collection("user-following").document(uid)
let userFollowersDoc = FirestoreConstants.FollowersCollection.document(uid).collection("user-followers").document(currentUid)
try await Firestore.firestore().runTransaction { transaction, errorPointer in
do {
let userDoc = FirestoreConstants.UserCollection.document(uid)
let currentUserDoc = FirestoreConstants.UserCollection.document(currentUid)
transaction.updateData(["stats.followers": FieldValue.increment(Int64(1))], forDocument: userDoc)
transaction.updateData(["stats.following": FieldValue.increment(Int64(1))], forDocument: currentUserDoc)
transaction.setData([:], forDocument: userFollowingDoc)
transaction.setData([:], forDocument: userFollowersDoc)
} catch {
errorPointer?.pointee = error as NSError
return nil
}
return nil
}
}
import UserNotifications
import OneSignalExtension
class NotificationService: UNNotificationServiceExtension {
var contentHandler: ((UNNotificationContent) -> Void)?
var bestAttemptContent: UNMutableNotificationContent?
var receivedRequest: UNNotificationRequest!
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
self.contentHandler = contentHandler
self.receivedRequest = request
bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
guard let bestAttemptContent = bestAttemptContent else { return }
// Configure the notification content
OneSignalExtension.didReceiveNotificationExtensionRequest(
self.receivedRequest,
with: bestAttemptContent,
withContentHandler: contentHandler
)
// Add custom notification handling if needed
if let userInfo = bestAttemptContent.userInfo as? [String: Any] {
// Example: Add a custom category for follow notifications
if let notificationType = userInfo["type"] as? String, notificationType == "follow" {
bestAttemptContent.categoryIdentifier = "FOLLOW_CATEGORY"
}
// Example: Modify the notification body based on the type
if let senderName = userInfo["senderName"] as? String {
bestAttemptContent.body = "\(senderName) \(bestAttemptContent.body)"
}
}
// Add a custom sound
bestAttemptContent.sound = UNNotificationSound.default
}
override func serviceExtensionTimeWillExpire() {
// Called just before the extension will be terminated by the system.
guard let contentHandler = contentHandler,
let bestAttemptContent = bestAttemptContent else { return }
// Use this as an opportunity to deliver your "best attempt" at modified content
OneSignalExtension.serviceExtensionTimeWillExpireRequest(
self.receivedRequest,
with: bestAttemptContent
)
contentHandler(bestAttemptContent)
}
}
Подробнее здесь: https://stackoverflow.com/questions/794 ... llow-swift
OneSignal Отправить push -уведомление пользователям, когда они получат новое следующее Swift ⇐ IOS
Программируем под IOS
1738681834
Anonymous
Я новый разработчик и настроил OneSignal с моим приложением для iOS, а моя база данных - Firebase, однако я изо всех сил пытаюсь найти, как отправить push -уведомления определенным пользователям, когда они получат новое следствие, может ли кто -нибудь помочь
Это коды: < /p>
static func follow(uid: String) async throws {
guard let currentUid = Auth.auth().currentUser?.uid else { return }
let userFollowingDoc = FirestoreConstants.FollowingCollection.document(currentUid).collection("user-following").document(uid)
let userFollowersDoc = FirestoreConstants.FollowersCollection.document(uid).collection("user-followers").document(currentUid)
try await Firestore.firestore().runTransaction { transaction, errorPointer in
do {
let userDoc = FirestoreConstants.UserCollection.document(uid)
let currentUserDoc = FirestoreConstants.UserCollection.document(currentUid)
transaction.updateData(["stats.followers": FieldValue.increment(Int64(1))], forDocument: userDoc)
transaction.updateData(["stats.following": FieldValue.increment(Int64(1))], forDocument: currentUserDoc)
transaction.setData([:], forDocument: userFollowingDoc)
transaction.setData([:], forDocument: userFollowersDoc)
} catch {
errorPointer?.pointee = error as NSError
return nil
}
return nil
}
}
import UserNotifications
import OneSignalExtension
class NotificationService: UNNotificationServiceExtension {
var contentHandler: ((UNNotificationContent) -> Void)?
var bestAttemptContent: UNMutableNotificationContent?
var receivedRequest: UNNotificationRequest!
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
self.contentHandler = contentHandler
self.receivedRequest = request
bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
guard let bestAttemptContent = bestAttemptContent else { return }
// Configure the notification content
OneSignalExtension.didReceiveNotificationExtensionRequest(
self.receivedRequest,
with: bestAttemptContent,
withContentHandler: contentHandler
)
// Add custom notification handling if needed
if let userInfo = bestAttemptContent.userInfo as? [String: Any] {
// Example: Add a custom category for follow notifications
if let notificationType = userInfo["type"] as? String, notificationType == "follow" {
bestAttemptContent.categoryIdentifier = "FOLLOW_CATEGORY"
}
// Example: Modify the notification body based on the type
if let senderName = userInfo["senderName"] as? String {
bestAttemptContent.body = "\(senderName) \(bestAttemptContent.body)"
}
}
// Add a custom sound
bestAttemptContent.sound = UNNotificationSound.default
}
override func serviceExtensionTimeWillExpire() {
// Called just before the extension will be terminated by the system.
guard let contentHandler = contentHandler,
let bestAttemptContent = bestAttemptContent else { return }
// Use this as an opportunity to deliver your "best attempt" at modified content
OneSignalExtension.serviceExtensionTimeWillExpireRequest(
self.receivedRequest,
with: bestAttemptContent
)
contentHandler(bestAttemptContent)
}
}
Подробнее здесь: [url]https://stackoverflow.com/questions/79411319/onesignal-send-push-notification-to-users-when-they-get-a-new-follow-swift[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия