use core::ffi::*;
use core::ptr::NonNull;
use objc2::__framework_prelude::*;
use objc2_foundation::*;
use crate::*;
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct UNAuthorizationOptions(pub NSUInteger);
bitflags::bitflags! {
impl UNAuthorizationOptions: NSUInteger {
#[doc(alias = "UNAuthorizationOptionBadge")]
const Badge = 1<<0;
#[doc(alias = "UNAuthorizationOptionSound")]
const Sound = 1<<1;
#[doc(alias = "UNAuthorizationOptionAlert")]
const Alert = 1<<2;
#[doc(alias = "UNAuthorizationOptionCarPlay")]
const CarPlay = 1<<3;
#[doc(alias = "UNAuthorizationOptionCriticalAlert")]
const CriticalAlert = 1<<4;
#[doc(alias = "UNAuthorizationOptionProvidesAppNotificationSettings")]
const ProvidesAppNotificationSettings = 1<<5;
#[doc(alias = "UNAuthorizationOptionProvisional")]
const Provisional = 1<<6;
#[doc(alias = "UNAuthorizationOptionAnnouncement")]
#[deprecated = "Announcement authorization is always included"]
const Announcement = 1<<7;
#[doc(alias = "UNAuthorizationOptionTimeSensitive")]
#[deprecated = "Use time-sensitive entitlement"]
const TimeSensitive = 1<<8;
}
}
unsafe impl Encode for UNAuthorizationOptions {
const ENCODING: Encoding = NSUInteger::ENCODING;
}
unsafe impl RefEncode for UNAuthorizationOptions {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
pub static UNAuthorizationOptionNone: UNAuthorizationOptions = UNAuthorizationOptions(0);
extern_class!(
#[unsafe(super(NSObject))]
#[derive(Debug, PartialEq, Eq, Hash)]
pub struct UNUserNotificationCenter;
);
extern_conformance!(
unsafe impl NSObjectProtocol for UNUserNotificationCenter {}
);
impl UNUserNotificationCenter {
extern_methods!(
#[unsafe(method(delegate))]
#[unsafe(method_family = none)]
pub fn delegate(
&self,
) -> Option<Retained<ProtocolObject<dyn UNUserNotificationCenterDelegate>>>;
#[unsafe(method(setDelegate:))]
#[unsafe(method_family = none)]
pub fn setDelegate(
&self,
delegate: Option<&ProtocolObject<dyn UNUserNotificationCenterDelegate>>,
);
#[unsafe(method(supportsContentExtensions))]
#[unsafe(method_family = none)]
pub fn supportsContentExtensions(&self) -> bool;
#[unsafe(method(currentNotificationCenter))]
#[unsafe(method_family = none)]
pub fn currentNotificationCenter() -> Retained<UNUserNotificationCenter>;
#[unsafe(method(init))]
#[unsafe(method_family = init)]
pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
#[cfg(feature = "block2")]
#[unsafe(method(requestAuthorizationWithOptions:completionHandler:))]
#[unsafe(method_family = none)]
pub fn requestAuthorizationWithOptions_completionHandler(
&self,
options: UNAuthorizationOptions,
completion_handler: &block2::DynBlock<dyn Fn(Bool, *mut NSError)>,
);
#[cfg(feature = "UNNotificationCategory")]
#[unsafe(method(setNotificationCategories:))]
#[unsafe(method_family = none)]
pub fn setNotificationCategories(&self, categories: &NSSet<UNNotificationCategory>);
#[cfg(all(feature = "UNNotificationCategory", feature = "block2"))]
#[unsafe(method(getNotificationCategoriesWithCompletionHandler:))]
#[unsafe(method_family = none)]
pub fn getNotificationCategoriesWithCompletionHandler(
&self,
completion_handler: &block2::DynBlock<dyn Fn(NonNull<NSSet<UNNotificationCategory>>)>,
);
#[cfg(all(feature = "UNNotificationSettings", feature = "block2"))]
#[unsafe(method(getNotificationSettingsWithCompletionHandler:))]
#[unsafe(method_family = none)]
pub fn getNotificationSettingsWithCompletionHandler(
&self,
completion_handler: &block2::DynBlock<dyn Fn(NonNull<UNNotificationSettings>)>,
);
#[cfg(all(feature = "UNNotificationRequest", feature = "block2"))]
#[unsafe(method(addNotificationRequest:withCompletionHandler:))]
#[unsafe(method_family = none)]
pub fn addNotificationRequest_withCompletionHandler(
&self,
request: &UNNotificationRequest,
completion_handler: Option<&block2::DynBlock<dyn Fn(*mut NSError)>>,
);
#[cfg(all(feature = "UNNotificationRequest", feature = "block2"))]
#[unsafe(method(getPendingNotificationRequestsWithCompletionHandler:))]
#[unsafe(method_family = none)]
pub fn getPendingNotificationRequestsWithCompletionHandler(
&self,
completion_handler: &block2::DynBlock<dyn Fn(NonNull<NSArray<UNNotificationRequest>>)>,
);
#[unsafe(method(removePendingNotificationRequestsWithIdentifiers:))]
#[unsafe(method_family = none)]
pub fn removePendingNotificationRequestsWithIdentifiers(
&self,
identifiers: &NSArray<NSString>,
);
#[unsafe(method(removeAllPendingNotificationRequests))]
#[unsafe(method_family = none)]
pub fn removeAllPendingNotificationRequests(&self);
#[cfg(all(feature = "UNNotification", feature = "block2"))]
#[unsafe(method(getDeliveredNotificationsWithCompletionHandler:))]
#[unsafe(method_family = none)]
pub fn getDeliveredNotificationsWithCompletionHandler(
&self,
completion_handler: &block2::DynBlock<dyn Fn(NonNull<NSArray<UNNotification>>)>,
);
#[unsafe(method(removeDeliveredNotificationsWithIdentifiers:))]
#[unsafe(method_family = none)]
pub fn removeDeliveredNotificationsWithIdentifiers(&self, identifiers: &NSArray<NSString>);
#[unsafe(method(removeAllDeliveredNotifications))]
#[unsafe(method_family = none)]
pub fn removeAllDeliveredNotifications(&self);
#[cfg(feature = "block2")]
#[unsafe(method(setBadgeCount:withCompletionHandler:))]
#[unsafe(method_family = none)]
pub fn setBadgeCount_withCompletionHandler(
&self,
new_badge_count: NSInteger,
completion_handler: Option<&block2::DynBlock<dyn Fn(*mut NSError)>>,
);
);
}
impl UNUserNotificationCenter {
extern_methods!(
#[unsafe(method(new))]
#[unsafe(method_family = new)]
pub unsafe fn new() -> Retained<Self>;
);
}
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct UNNotificationPresentationOptions(pub NSUInteger);
bitflags::bitflags! {
impl UNNotificationPresentationOptions: NSUInteger {
#[doc(alias = "UNNotificationPresentationOptionBadge")]
const Badge = 1<<0;
#[doc(alias = "UNNotificationPresentationOptionSound")]
const Sound = 1<<1;
#[doc(alias = "UNNotificationPresentationOptionAlert")]
#[deprecated]
const Alert = 1<<2;
#[doc(alias = "UNNotificationPresentationOptionList")]
const List = 1<<3;
#[doc(alias = "UNNotificationPresentationOptionBanner")]
const Banner = 1<<4;
}
}
unsafe impl Encode for UNNotificationPresentationOptions {
const ENCODING: Encoding = NSUInteger::ENCODING;
}
unsafe impl RefEncode for UNNotificationPresentationOptions {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
pub static UNNotificationPresentationOptionNone: UNNotificationPresentationOptions =
UNNotificationPresentationOptions(0);
extern_protocol!(
pub unsafe trait UNUserNotificationCenterDelegate: NSObjectProtocol {
#[cfg(all(feature = "UNNotification", feature = "block2"))]
#[optional]
#[unsafe(method(userNotificationCenter:willPresentNotification:withCompletionHandler:))]
#[unsafe(method_family = none)]
fn userNotificationCenter_willPresentNotification_withCompletionHandler(
&self,
center: &UNUserNotificationCenter,
notification: &UNNotification,
completion_handler: &block2::DynBlock<dyn Fn(UNNotificationPresentationOptions)>,
);
#[cfg(all(feature = "UNNotificationResponse", feature = "block2"))]
#[optional]
#[unsafe(method(userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:))]
#[unsafe(method_family = none)]
fn userNotificationCenter_didReceiveNotificationResponse_withCompletionHandler(
&self,
center: &UNUserNotificationCenter,
response: &UNNotificationResponse,
completion_handler: &block2::DynBlock<dyn Fn()>,
);
#[cfg(feature = "UNNotification")]
#[optional]
#[unsafe(method(userNotificationCenter:openSettingsForNotification:))]
#[unsafe(method_family = none)]
fn userNotificationCenter_openSettingsForNotification(
&self,
center: &UNUserNotificationCenter,
notification: Option<&UNNotification>,
);
}
);