Skip to content
This repository has been archived by the owner on Feb 17, 2023. It is now read-only.

Added most of User Notifications Framework #119

Merged
merged 2 commits into from
Nov 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ default = [
"core_foundation",
"core_graphics",
"core_ml",
"core_location",
"foundation",
"kernel",
"natural_language",
Expand All @@ -54,6 +55,7 @@ compression = []
contacts = ["foundation"]
core_foundation = ["kernel"]
core_graphics = ["objective_c_runtime"]
core_location = []
core_ml = ["foundation"]
foundation = [
"objective_c_runtime",
Expand Down
67 changes: 59 additions & 8 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,38 +1,89 @@
fn main() {
let target = std::env::var("TARGET").unwrap();
#[cfg(any(target_os = "ios", target_os = "tvos", target_os = "watchos"))]
#[cfg(feature = "uikit")]
println!("cargo:rustc-link-lib=framework=UIKit");

if target.contains("apple-ios") {
#[cfg(feature = "uikit")]
println!("cargo:rustc-link-lib=framework=UIKit");
} else if target.contains("apple-darwin") {
#[cfg(feature = "appkit")]
println!("cargo:rustc-link-lib=framework=AppKit");
}
#[cfg(target_os = "macos")]
#[cfg(feature = "appkit")]
println!("cargo:rustc-link-lib=framework=AppKit");

#[cfg(any(
target_os = "ios",
target_os = "macos",
target_os = "tvos",
target_os = "watchos"
))]
#[cfg(feature = "user_notifications")]
println!("cargo:rustc-link-lib=framework=UserNotifications");

#[cfg(any(
target_os = "ios",
target_os = "macos",
target_os = "tvos",
target_os = "watchos"
))]
#[cfg(feature = "foundation")]
println!("cargo:rustc-link-lib=framework=Foundation");

#[cfg(any(
target_os = "ios",
target_os = "macos",
target_os = "tvos",
target_os = "watchos"
))]
#[cfg(feature = "compression")]
println!("cargo:rustc-link-lib=dylib=Compression");

#[cfg(any(
target_os = "ios",
target_os = "macos",
target_os = "tvos",
target_os = "watchos"
))]
#[cfg(feature = "natural_language")]
println!("cargo:rustc-link-lib=framework=NaturalLanguage");

#[cfg(any(target_os = "ios", target_os = "tvos"))]
#[cfg(feature = "background_tasks")]
println!("cargo:rustc-link-lib=framework=BackgroundTasks");

#[cfg(any(
target_os = "ios",
target_os = "macos",
target_os = "tvos",
target_os = "watchos"
))]
#[cfg(feature = "core_graphics")]
println!("cargo:rustc-link-lib=framework=CoreGraphics");

#[cfg(any(
target_os = "ios",
target_os = "macos",
target_os = "tvos",
target_os = "watchos"
))]
#[cfg(feature = "core_foundation")]
println!("cargo:rustc-link-lib=framework=CoreFoundation");

#[cfg(any(target_os = "ios", target_os = "macos", target_os = "watchos"))]
#[cfg(feature = "contacts")]
println!("cargo:rustc-link-lib=framework=Contacts");

#[cfg(any(
target_os = "ios",
target_os = "macos",
target_os = "tvos",
target_os = "watchos"
))]
#[cfg(feature = "core_ml")]
println!("cargo:rustc-link-lib=framework=CoreML");

#[cfg(any(
target_os = "ios",
target_os = "macos",
target_os = "tvos",
target_os = "watchos"
))]
#[cfg(feature = "core_location")]
println!("cargo:rustc-link-lib=framework=CoreLocation");
}
1 change: 1 addition & 0 deletions examples/console.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fn main() {}
2 changes: 2 additions & 0 deletions src/core_location.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mod cl_region;
pub use cl_region::*;
10 changes: 10 additions & 0 deletions src/core_location/cl_region.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use rust_macios_objective_c_runtime_proc_macros::interface_impl;

use crate::objective_c_runtime::{macros::object, traits::PNSObject};

object! {
unsafe pub struct CLRegion;
}

#[interface_impl(NSObject)]
impl CLRegion {}
7 changes: 7 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,23 @@ pub mod background_tasks;
pub mod compression;
#[cfg(feature = "contacts")]
pub mod contacts;

#[cfg(feature = "core_foundation")]
pub mod core_foundation;

#[cfg(feature = "core_graphics")]
pub mod core_graphics;
#[cfg(feature = "core_location")]
pub mod core_location;

#[cfg(feature = "core_ml")]
pub mod core_ml;

#[cfg(feature = "foundation")]
pub mod foundation;
#[cfg(feature = "kernel")]
pub mod kernel;

#[cfg(feature = "natural_language")]
pub mod natural_language;
#[cfg(feature = "objective_c_runtime")]
Expand Down
3 changes: 3 additions & 0 deletions src/uikit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ pub use ns_layout_anchor::*;
pub use ns_layout_constraint::*;
pub use ns_layout_x_axis_anchor::*;
pub use ns_layout_y_axis_anchor::*;

mod ui_scene;
pub use ui_scene::*;
5 changes: 5 additions & 0 deletions src/uikit/ui_scene.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use crate::objective_c_runtime::macros::object;

object! {
unsafe pub struct UIScene;
}
52 changes: 49 additions & 3 deletions src/user_notifications.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Push user-facing notifications to the user’s device from a server, or generate them locally from your app.

use crate::foundation::NSString;

/* Notification Management
*/

Expand All @@ -24,23 +26,67 @@ pub use un_notification::*;
/* Notification Content
*/

mod un_notification_content_providing;
pub use un_notification_content_providing::*;

mod un_notification_action_icon;
pub use un_notification_action_icon::*;

mod un_mutable_notification_content;
pub use un_mutable_notification_content::*;

mod un_notification_content;
pub use un_notification_content::*;

mod un_notification_attachment;
pub use un_notification_attachment::*;

mod un_notification_sound;
pub use un_notification_sound::*;

pub type UNNotificationSoundName = NSString;

/* Triggers
*/

mod un_calendar_notification_trigger;
pub use un_calendar_notification_trigger::*;

mod un_time_interval_notification_trigger;
pub use un_time_interval_notification_trigger::*;

mod un_location_notification_trigger;
pub use un_location_notification_trigger::*;

mod un_push_notification_trigger;
pub use un_push_notification_trigger::*;

mod un_notification_trigger;
pub use un_notification_trigger::*;

/* Notification Categories and User Actions
*/

mod un_notification_category;
pub use un_notification_category::*;

mod un_notification_action;
pub use un_notification_action::*;

mod un_text_input_notification_action;
pub use un_text_input_notification_action::*;

/* Notification Responses
*/

mod un_notification_response;
pub use un_notification_response::*;

/* Notification Categories and User Actions
mod un_text_input_notification_response;
pub use un_text_input_notification_response::*;

/* Notification Service App Extension
*/

mod un_notification_category;
pub use un_notification_category::*;
mod un_notification_service_extension;
pub use un_notification_service_extension::*;
53 changes: 53 additions & 0 deletions src/user_notifications/un_calendar_notification_trigger.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
use objc::{msg_send, sel, sel_impl};
use rust_macios_objective_c_runtime_proc_macros::interface_impl;

use crate::{
foundation::{NSDate, NSDateComponents},
objective_c_runtime::{macros::object, traits::FromId},
utils::to_optional,
};

use super::IUNNotificationTrigger;

object! {
unsafe pub struct UNCalendarNotificationTrigger;
}

impl IUNNotificationTrigger for UNCalendarNotificationTrigger {}

#[interface_impl(UNNotificationTrigger)]
impl UNCalendarNotificationTrigger {
/* Creating a Calendar Trigger
*/

/// Creates a calendar trigger using the date components parameter.
#[method]
pub fn trigger_with_date_matching_components_repeats(
date_components: NSDateComponents,
repeats: bool,
) -> Self
where
Self: Sized + FromId,
{
unsafe {
Self::from_id(
msg_send![Self::m_class(), triggerWithDateMatchingComponents: date_components repeats: repeats],
)
}
}

/* Getting the Trigger Information
*/

/// The next date at which the trigger conditions are met.
#[method]
pub fn next_trigger_date(&self) -> Option<NSDate> {
unsafe { to_optional(msg_send![self.m_self(), nextTriggerDate]) }
}

/// The date components to construct this object.
#[property]
pub fn date_components(&self) -> NSDateComponents {
unsafe { NSDateComponents::from_id(msg_send![self.m_self(), dateComponents]) }
}
}
44 changes: 44 additions & 0 deletions src/user_notifications/un_location_notification_trigger.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use rust_macios_objective_c_runtime_proc_macros::interface_impl;

use crate::objective_c_runtime::macros::object;

use super::IUNNotificationTrigger;

object! {
/// A trigger condition that causes the system to deliver a notification when the user’s device enters or exits a geographic region you specify.
unsafe pub struct UNLocationNotificationTrigger;
}

impl IUNNotificationTrigger for UNLocationNotificationTrigger {}

#[interface_impl(UNNotificationTrigger)]
impl UNLocationNotificationTrigger {
/* Creating a Location Trigger
*/

/// Creates a location trigger using the region parameter.
///
/// Required features: `"core_location"`
#[method]
fn trigger_with_region_repeats(region: crate::core_location::CLRegion, repeats: bool) -> Self
where
Self: Sized + crate::objective_c_runtime::traits::FromId,
{
use objc::{msg_send, sel, sel_impl};

unsafe {
Self::from_id(msg_send![Self::m_class(), triggerWithRegion: region repeats: repeats])
}
}

/// The region used to determine when the system sends the notification.
///
/// Required features: `"core_location"`
#[property]
fn region(&self) -> crate::core_location::CLRegion {
use crate::objective_c_runtime::traits::FromId;
use objc::{msg_send, sel, sel_impl};

unsafe { crate::core_location::CLRegion::from_id(msg_send![self.m_self(), region]) }
}
}
Loading