#[cfg(feature = "block2")]
use block2::*;
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);
impl UNAuthorizationOptions {
pub const UNAuthorizationOptionBadge: Self = Self(1 << 0);
pub const UNAuthorizationOptionSound: Self = Self(1 << 1);
pub const UNAuthorizationOptionAlert: Self = Self(1 << 2);
pub const UNAuthorizationOptionCarPlay: Self = Self(1 << 3);
pub const UNAuthorizationOptionCriticalAlert: Self = Self(1 << 4);
pub const UNAuthorizationOptionProvidesAppNotificationSettings: Self = Self(1 << 5);
pub const UNAuthorizationOptionProvisional: Self = Self(1 << 6);
#[deprecated = "Announcement authorization is always included"]
pub const UNAuthorizationOptionAnnouncement: Self = Self(1 << 7);
#[deprecated = "Use time-sensitive entitlement"]
pub const UNAuthorizationOptionTimeSensitive: Self = Self(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!(
#[derive(Debug, PartialEq, Eq, Hash)]
pub struct UNUserNotificationCenter;
unsafe impl ClassType for UNUserNotificationCenter {
type Super = NSObject;
type Mutability = InteriorMutable;
}
);
unsafe impl NSObjectProtocol for UNUserNotificationCenter {}
extern_methods!(
unsafe impl UNUserNotificationCenter {
#[method_id(@__retain_semantics Other delegate)]
pub unsafe fn delegate(
&self,
) -> Option<Id<ProtocolObject<dyn UNUserNotificationCenterDelegate>>>;
#[method(setDelegate:)]
pub unsafe fn setDelegate(
&self,
delegate: Option<&ProtocolObject<dyn UNUserNotificationCenterDelegate>>,
);
#[method(supportsContentExtensions)]
pub unsafe fn supportsContentExtensions(&self) -> bool;
#[method_id(@__retain_semantics Other currentNotificationCenter)]
pub unsafe fn currentNotificationCenter() -> Id<UNUserNotificationCenter>;
#[method_id(@__retain_semantics Init init)]
pub unsafe fn init(this: Allocated<Self>) -> Id<Self>;
#[cfg(feature = "block2")]
#[method(requestAuthorizationWithOptions:completionHandler:)]
pub unsafe fn requestAuthorizationWithOptions_completionHandler(
&self,
options: UNAuthorizationOptions,
completion_handler: &Block<dyn Fn(Bool, *mut NSError)>,
);
#[cfg(feature = "UNNotificationCategory")]
#[method(setNotificationCategories:)]
pub unsafe fn setNotificationCategories(&self, categories: &NSSet<UNNotificationCategory>);
#[cfg(all(feature = "UNNotificationCategory", feature = "block2"))]
#[method(getNotificationCategoriesWithCompletionHandler:)]
pub unsafe fn getNotificationCategoriesWithCompletionHandler(
&self,
completion_handler: &Block<dyn Fn(NonNull<NSSet<UNNotificationCategory>>)>,
);
#[cfg(all(feature = "UNNotificationSettings", feature = "block2"))]
#[method(getNotificationSettingsWithCompletionHandler:)]
pub unsafe fn getNotificationSettingsWithCompletionHandler(
&self,
completion_handler: &Block<dyn Fn(NonNull<UNNotificationSettings>)>,
);
#[cfg(all(feature = "UNNotificationRequest", feature = "block2"))]
#[method(addNotificationRequest:withCompletionHandler:)]
pub unsafe fn addNotificationRequest_withCompletionHandler(
&self,
request: &UNNotificationRequest,
completion_handler: Option<&Block<dyn Fn(*mut NSError)>>,
);
#[cfg(all(feature = "UNNotificationRequest", feature = "block2"))]
#[method(getPendingNotificationRequestsWithCompletionHandler:)]
pub unsafe fn getPendingNotificationRequestsWithCompletionHandler(
&self,
completion_handler: &Block<dyn Fn(NonNull<NSArray<UNNotificationRequest>>)>,
);
#[method(removePendingNotificationRequestsWithIdentifiers:)]
pub unsafe fn removePendingNotificationRequestsWithIdentifiers(
&self,
identifiers: &NSArray<NSString>,
);
#[method(removeAllPendingNotificationRequests)]
pub unsafe fn removeAllPendingNotificationRequests(&self);
#[cfg(all(feature = "UNNotification", feature = "block2"))]
#[method(getDeliveredNotificationsWithCompletionHandler:)]
pub unsafe fn getDeliveredNotificationsWithCompletionHandler(
&self,
completion_handler: &Block<dyn Fn(NonNull<NSArray<UNNotification>>)>,
);
#[method(removeDeliveredNotificationsWithIdentifiers:)]
pub unsafe fn removeDeliveredNotificationsWithIdentifiers(
&self,
identifiers: &NSArray<NSString>,
);
#[method(removeAllDeliveredNotifications)]
pub unsafe fn removeAllDeliveredNotifications(&self);
#[cfg(feature = "block2")]
#[method(setBadgeCount:withCompletionHandler:)]
pub unsafe fn setBadgeCount_withCompletionHandler(
&self,
new_badge_count: NSInteger,
completion_handler: Option<&Block<dyn Fn(*mut NSError)>>,
);
}
);
extern_methods!(
unsafe impl UNUserNotificationCenter {
#[method_id(@__retain_semantics New new)]
pub unsafe fn new() -> Id<Self>;
}
);
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct UNNotificationPresentationOptions(pub NSUInteger);
impl UNNotificationPresentationOptions {
pub const UNNotificationPresentationOptionBadge: Self = Self(1 << 0);
pub const UNNotificationPresentationOptionSound: Self = Self(1 << 1);
#[deprecated]
pub const UNNotificationPresentationOptionAlert: Self = Self(1 << 2);
pub const UNNotificationPresentationOptionList: Self = Self(1 << 3);
pub const UNNotificationPresentationOptionBanner: Self = Self(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]
#[method(userNotificationCenter:willPresentNotification:withCompletionHandler:)]
unsafe fn userNotificationCenter_willPresentNotification_withCompletionHandler(
&self,
center: &UNUserNotificationCenter,
notification: &UNNotification,
completion_handler: &Block<dyn Fn(UNNotificationPresentationOptions)>,
);
#[cfg(all(feature = "UNNotificationResponse", feature = "block2"))]
#[optional]
#[method(userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:)]
unsafe fn userNotificationCenter_didReceiveNotificationResponse_withCompletionHandler(
&self,
center: &UNUserNotificationCenter,
response: &UNNotificationResponse,
completion_handler: &Block<dyn Fn()>,
);
#[cfg(feature = "UNNotification")]
#[optional]
#[method(userNotificationCenter:openSettingsForNotification:)]
unsafe fn userNotificationCenter_openSettingsForNotification(
&self,
center: &UNUserNotificationCenter,
notification: Option<&UNNotification>,
);
}
unsafe impl ProtocolType for dyn UNUserNotificationCenterDelegate {}
);