SPLocalNotificationManager

public class SPLocalNotificationManager : NSObject

Helper for showing local notifications. For example, a turbulence alert when the app is in the background.

  • Use shared instance.

    Declaration

    Swift

    public static let shared: SPLocalNotificationManager
  • Check current notifications usage permission. Will be auto-requested if the status is notDetermined.

    Declaration

    Swift

    public func checkNotificationSettings(completion: ((_ status: UNAuthorizationStatus) -> Void)? = nil)

    Parameters

    completion

    A block to handle authorization status. For example, ask the user to turn on when denied. Optional.

  • Schedule a local notification to be shown immediately.

    Declaration

    Swift

    @discardableResult
    public func scheduleNotification(title: String,
                                     body: String,
                                     sound: String? = "default",
                                     soundEnabled: Bool = true,
                                     contentCategoryIdentifier: String? = nil,
                                     timeInterval: TimeInterval = 1,
                                     identifier: String = UUID().uuidString,
                                     userInfo: [String: Any]? = nil) -> String

    Parameters

    title

    A title of the notification.

    body

    A body text of a notification.

    sound

    Sound name. Could be a custom sound file name located in the app bundle or “default” to play the default system sound. Set nil to have a silent notification.

    contentCategoryIdentifier

    UNMutableNotificationContent.categoryIdentifier for the notification. Optional.

    timeInterval

    Used for UNTimeIntervalNotificationTrigger to schedule the notification.

    identifier

    Set a custom identifier for the notification. Optional.

    userInfo

    The custom data to associate with the notification.

  • Schedule a local notification to be shown immediately.

    Declaration

    Swift

    @discardableResult
    public func scheduleNotification(content: UNNotificationContent,
                                     timeInterval: TimeInterval = 1,
                                     identifier: String = UUID().uuidString) -> String

    Parameters

    content

    A notification content object.

    timeInterval

    Used for UNTimeIntervalNotificationTrigger to schedule the notification.

    identifier

    Set a custom identifier for the notification. Optional.