Push Notifications

See https://appspanel.readme.io/docs/push-notifications-v5 and https://appspanel.readme.io/docs/ios-push-notifications-v5

You can use this to request the permission for notifications

AppsPanel.requestPushPermission();

Retrieve push notification payloads (v1.0.8+)

The payload of the most recently received notification can be saved locally on the device and then accessed in Flutter through the bridge.

Android

You have to manually call the function to save the payload when the notification is tapped.

It would usually be done in your MainActivity through PushManager.saveNotificationContentToFile() and PushManager.shouldSaveNotificationContent.

This works for when the notification is tapped when the app is either in background or killed, there is currently no way to make this work for when the notification is tapped when the app is in foreground.

import android.os.Bundle
import com.appspanel.flutter_appspanel.PushManager
import io.flutter.embedding.android.FlutterActivity

class MainActivity: FlutterActivity() {
    private val pushManager = PushManager()

    override fun onCreate(savedInstanceState: Bundle?) {
        if (pushManager.shouldSaveNotificationContent(intent)) {
            pushManager.saveNotificationContentToFile(this, intent)
        }
        super.onCreate(savedInstanceState)
    }
}

iOS

You have to manually call the function to save the payload when the notification is tapped

It would usually be done in AppDelegate, in the userNotificationCenter(_ center: didReceive: withCompletionHandler) function.

This works for when the notification is tapped when the app is killed, in background, or in foreground.

First import the module

import flutter_appspanel

Then create and initialize an instance of PushManager

// in the AppDelegate
private var pushManager: PushManager?

// inside application(application: didFinishLaunchingWithOptions:)
pushManager = PushManager(appDelegate: self)

// then add a call to `saveNotificationContentToFile` in this function
override func userNotificationCenter(
        _ center: UNUserNotificationCenter,
        didReceive response: UNNotificationResponse,
        withCompletionHandler completionHandler: @escaping () -> Void
    ) {
        pushManager?.saveNotificationContentToFile(userInfo: response.notification.request.content.userInfo)
  		// rest of the function
    }

Flutter

Finally in Flutter you now have access to 2 new functions inside AppsPanel.pushManager to retrieve and then clear the locally saved data.

final data = await AppsPanel.pushManager.getMostRecentPushData(autoDelete: false);
await AppsPanel.pushManager.deleteMostRecentPushData

// or directly with the default autoDelete to true, you can omit the call to `deleteMostRecentPushData`
final data = await AppsPanel.pushManager.getMostRecentPushData();