2016-08-17 2 views
1

버튼 동작에 대해 매주 알림을 설정하는 방법. 매주 응용 프로그램에 매주버튼 클릭시 매주 로컬 알림.

-(IBAction)buttonAction:(id)sender{ 
    UILocalNotification* localNotification = [[UILocalNotification alloc] init]; 
    localNotification.fireDate = [NSDate dateByAddingTimeInterval:60*60*24*7]; 
    localNotification.alertBody = @"Hello Message"; 
    localNotification.alertAction = @"Show me the item"; 
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; 
localNotification.repeatInterval = NSWeekCalendarUnit; 
} 

는 // 알림 메시지에 "Hello 메시지"

답변

1

스위프트 2.2 통지합니다 :

추가 :

localNotification.repeatInterval = .Weekday 

스위프트 3.0 :

let content: UNMutableNotificationContent = UNMutableNotificationContent() 

    content.title = "Title" 

    content.subtitle = "Subtitle" 

    content.body = "Hello Message" 

    let calendar = Calendar.current 

    let alarmTime = Date().addingTimeInterval(60*60*24*7) 
    let alarmTimeComponents = calendar.dateComponents([.weekday], from: alarmTime) 

    let trigger = UNCalendarNotificationTrigger(dateMatching: alarmTimeComponents, repeats: true) 

    let request = UNNotificationRequest(identifier: workoutAlarmIdentifier, 
             content: content, 
             trigger: trigger) 

    UNUserNotificationCenter.current().add(request) 
    { 
     (error) in // ... 
    } 
0
  • 이제 오후 2시 토 11월 5
  • 나는 선택기 2:10 오후 설정 한 토 십일 오
  • 로컬 알림 2:10 PM에 표시됩니다 토 11월 5
  • 입니다

    통지는 오후 2시 10분 토 11월 12일

    let ok = UNNotificationAction(identifier: "OKIdentifier", title: "Open", options: [.foreground]) 
        let cancel = UNNotificationAction(identifier: "CancelIdentifier", title: "Dismiss", options: []) 
        let category = UNNotificationCategory(identifier: "message", actions: [ok, cancel], intentIdentifiers: [], options: []) 
        UNUserNotificationCenter.current().setNotificationCategories([category]) 
    
        let content = UNMutableNotificationContent() 
        content.body = "open the SAMPLE app" 
        content.categoryIdentifier = "message" 
    
        let alarmTime = datePicker.date 
        let alarmTimeComponent = Calendar.current.dateComponents([.hour, .minute, .weekday], from: alarmTime) 
        let trigger = UNCalendarNotificationTrigger(dateMatching: alarmTimeComponent, repeats: true) 
    
        let request = UNNotificationRequest(identifier:"five second", content: content, trigger: trigger) 
        UNUserNotificationCenter.current().add(request){(error) in 
         if (error != nil){ 
          //handle here 
          print("error : \(error)" ) 
         } 
        } 
    
에 통보되고 계속됩니다