Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implement Notification Service and Content Extension in Dynamic Framework

I have implemented Extension Notification Service and Notification Content Extension in my demo app and it’s working absolutely fine.

Now, I have to implement it in my framework. Means I’m working on dynamic framework which are support as like chat application. In framework all screens are created programatically, Its doesn’t contains any storyboard or XIB.

I have setup all required configuration for Notification Service Extension and Notification Content Extension same as like my demo app in framework. Everything is same as per my double check on it.

I’m struggling to implement Notification Service Extension and Notification Content Extension.

Should I need to create Notification Content programmatically instead of Storyboard ? Should I need to add target dependencies ? What I’m missing ?

On Dragging notification it's doesn't show me notification content.

Below is the code which I’m currently using for local notification for testing. This code is working in demo app.

@available(iOS 10.0, *)
func scheduleNotification() {

    UNUserNotificationCenter.current().delegate = self

    let content = UNMutableNotificationContent()
    content.title = "Notification"
    content.body = "We will remind you that your notification demo is performed well."
    content.sound = UNNotificationSound.default()
    content.categoryIdentifier = "myNotificationCategory"
    content.userInfo = ["Image" as AnyHashable: "https://codepo8.github.io/canvas-images-and-pixels/img/horse.png"]

    let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 5, repeats: false)
    let request = UNNotificationRequest(identifier: "request", content: content, trigger: trigger)
    UNUserNotificationCenter.current().add(request) { (error) in
        if error != nil {
            print("Error to add notification: \(error!.localizedDescription)")
        } else {
            print("Notification added")
        }
    }
}

I’m also testing it by debugging, but didReceive(_ notification: UNNotification) is also not calling.

I’m stuck ! Please help me? Help will be appreciated.

like image 877
Sagar Chauhan Avatar asked Apr 27 '18 08:04

Sagar Chauhan


1 Answers

I am getting your point regarding Notification Service Extension and Notification Content Extension to be added in your private framework. So you framework contains sharedInstance, that's why you are not able to implement both extension in your framework because it is not allowed.

So there are solution for that to create one small framework which contains code related to methods of both your extension, this method will be class method. It contains code which populate your notification services.

  1. Create new small framework which contains class methods and code related to Notification Content Extension and Notification Service Extension.

  2. Add this framework inside your application with your private framework.

  3. Add Notification Content Extension and Notification Service Extension Target inside your application and implement required method, call relative method from application to your notification framework.

You will get solution using this, but there is one more framework you need to add in your application

like image 195
Prashant Tukadiya Avatar answered Oct 13 '22 20:10

Prashant Tukadiya