2017-03-24 2 views
0

많은 것을 시도했지만 (예) 2 일 또는 5 일에 경고를 트리거하는 데 사용할 명령을 파악할 수없는 것처럼 보입니다. 시간. 누구든지 나를 도울 수 있습니까? 내가 할 수있는 일은 다음과 같습니다.일정 시간이 경과 한 후 트리거 Xcode 알림 (빠른 3)

var number = 3 
var repeat = day 
*Code with 'number' and 'repeat' in it.* 

그래서이 경우 3 일 내에 경고를 보냅니다. 여기있는 사람은 누구나 그렇게하는 법을 알고 있습니까? ^^

미리 감사드립니다.

+0

:


이것은 badge 속성입니다. 다음은 그 예입니다. https://code.tutsplus.com/tutorials/an-introduction-to-the-usernotifications-framework--cms-27250 – paper1111

+0

시도했지만 실제로 알아낼 수 없었습니다. 그것, 고마워! :) –

+0

실제로 "경고 메시지 보내기"라고 말하면 [this] (http://i.imgur.com/h4ph9mk.jpg)와 같은 메시지를 보내시겠습니까? – paper1111

답변

2

첫째, 통지가 필요로하는 파일의 상단에 배치 :

import UserNotifications 

그런 다음 다음과 같이 이제 알림을 요청 AppDelegate

let notifCenter = UNUserNotificationCenter.current() 
let options: UNAuthorizationOptions = [.alert, .badge, .sound] 
notifCenter.requestAuthorization(options: options, completionHandler: nil) 

application(_:didFinishLaunchingWithOptions:)이 장소 :

// timeInterval is in seconds, so 60*60*12*3 = 3 days, set repeats to true if you want to repeat the trigger 
let requestTrigger = UNTimeIntervalNotificationTrigger(timeInterval: (60*60*12*3), repeats: false) 

let requestContent = UNMutableNotificationContent() 
requestContent.title = "Title"  // insert your title 
requestContent.subtitle = "Subtitle" // insert your subtitle 
requestContent.body = "A body in notification." // insert your body 
requestContent.badge = 1 // the number that appears next to your app 
requestContent.sound = UNNotificationSound.default() 

// Request the notification 
let request = UNNotificationRequest(identifier "PutANameForTheNotificationHere", content: requestContent, trigger: requestTrigger 

// Post the notification! 
UNUserNotificationCenter.current().add(request) { error in 
    if let error = error { 
     // do something to the error 
    } else { 
     // posted successfully, do something like tell the user that notification was posted 
} 

이 코드 부분은 다음 세 가지를 수행합니다.

  1. 알림 컨텍스트
  2. 포스트 컨텍스트를 생성 트리거를 정의

당신이 통지와 함께 작업을 계속하려는 경우, 반응하는 방법에 대한 어떤 또한 회담, this tutorial 볼 때 사용자가 알림을 탭합니다.


참고 : UNMutableNotificationContext가 변경 가능한 이름에도 불구하고, UN 그냥 네임 스페이스입니다. 혼동하지 마십시오! 당신은 자막을 제공하는 경우


Notification

, 그것은 제목과 본문 사이에있을 것입니다. 먼저 자습서 구글에서 검색을 시도해야

enter image description here

+0

정말 고마워요! 나는 이것을 몇 가지 방법으로 시험해보고,이 질문에 답을 표시 할 것이다. :디 –

관련 문제