invertase / react-native-notifee

Moved to https://github.com/invertase/notifee
https://invertase.io/blog/open-sourcing-notifee
Other
465 stars 31 forks source link

Stuck setting up Notification Service Extension; Where is the extension in Xcode? #302

Closed fabyeah closed 3 years ago

fabyeah commented 3 years ago

I'm trying to follow the guide here: https://notifee.app/react-native/docs/ios/remote-notification-support

But I'm stuck at the "Use the extension helper" part. I don't have much experience with Xcode and don't know how to do this: "From the navigator select your extension". In my Navigator I have a folder NotifeeNotificationService, but that only contains NotificationService.swift and Info.plist. I cannot find this line of code anywhere in my project folder: #import "NotificationService.h" after which i'm supposed to add code.

What am I missing?

fabyeah commented 3 years ago

I guess the NotificationService.swift is the correct file, just swift instead of Obj-C. This is my file:

import UserNotifications

class NotificationService: UNNotificationServiceExtension {

    var contentHandler: ((UNNotificationContent) -> Void)?
    var bestAttemptContent: UNMutableNotificationContent?

    override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
        self.contentHandler = contentHandler
        bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)

        if let bestAttemptContent = bestAttemptContent {
            // Modify the notification content here...
            bestAttemptContent.title = "\(bestAttemptContent.title) [modified]"

            contentHandler(bestAttemptContent)
        }
    }

    override func serviceExtensionTimeWillExpire() {
        // Called just before the extension will be terminated by the system.
        // Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.
        if let contentHandler = contentHandler, let bestAttemptContent =  bestAttemptContent {
            contentHandler(bestAttemptContent)
        }
    }

}

How do I make the adjustments in swift? I can't import NotifeeExtensionHelper as Xcode says "No such module".

fabyeah commented 3 years ago

Also, I guess the rnfirebase.io guide on iOS setup has to be followed, as well, without changes, right?

https://rnfirebase.io/messaging/usage/ios-setup

helenaford commented 3 years ago

hey, sorry you've found this difficult. We have videos coming soon on the docs to help with demonstrating how to do this.

When you add the new target, in this case the notification service extension, ensure the language is Objective-C.

Screenshot 2021-05-13 at 15 36 25
fabyeah commented 3 years ago

Thanks, that did the trick! 👍🎉