如何在特定时间设置通知

时间:2017-08-28 13:29:44

标签: ios swift notifications

add_action( 'woocommerce_before_calculate_totals', 'add_custom_weight', 10, 1 );
function add_custom_weight( $cart ) {
    if ( is_admin() && ! defined( 'DOING_AJAX' ) )
        return;

    if ( did_action( 'woocommerce_before_calculate_totals' ) >= 2 )
        return;

    foreach ( $cart->get_cart() as $cart_item ) {
         //very simplified example - every item in cart will be 100 kg
        $cart_item['data']->set_weight( 100 );
    }
    // print_r( $cart->get_cart_contents_weight() ); // Only for testing (not on checkout page)
}

我希望在addAlarm中使用msg在日期发出消息通知。 我在main.swift中做了这个,但没有用 我该怎么办呢?在appdelegate添加这个? 我是swift的初学者。请帮忙......

2 个答案:

答案 0 :(得分:0)

let localNotification = UILocalNotification()
localNotification.alertBody = "Push Message"
if #available(iOS 8.2, *) {
localNotification.alertTitle = "Title"
} else {
// Fallback on earlier versions
}
let sec = 60
localNotification.fireDate = NSDate(timeIntervalSinceNow: Double(sec))
 UIApplication.sharedApplication().scheduleLocalNotification(localNotification)

在这里,您可以设置您想要设置本地推送所需的时间,例如:sec = 60(60秒)。

谢谢。

答案 1 :(得分:-4)

let calendar = Calendar.current
let components = DateComponents(year: 2018, month: 05, day: 06, hour: 20, minute: 22) // Set the date here when you want Notification
let date = calendar.date(from: components)
let comp2 = calendar.dateComponents([.year,.month,.day,.hour,.minute], from: date!)
let trigger = UNCalendarNotificationTrigger(dateMatching: comp2, repeats: true