Swift에 알림 메시지를 표시하여 iOS 애플리케이션에 의견을 표시하십시오.

5906 단어 SwiftiOS

코드


ViewController.swift
let ud = NSUserDefaults.standardUserDefaults()

override func viewDidAppear(animated: Bool) {
  if !ud.boolForKey("reviewed") {
    let alertController = UIAlertController(
      title: "おめでとうございます",
      message: "クリアありがとうございました。よろしければレビューを書いて頂けませんか?今後の開発の参考に致します", 
      preferredStyle: .Alert)

    let reviewAction = UIAlertAction(title: "レビューする", style: .Default) {
      action in
      let url = NSURL(string: "APP_STORE_URL")
      UIApplication.sharedApplication().openURL(url!)
      self.ud.setObject(true, forKey: "reviewed")
    }
    let yetAction = UIAlertAction(title: "まだレビューしない", style: .Default) {
      action in
      self.ud.setObject(false, forKey: "reviewed")
    }
    let neverAction = UIAlertAction(title: "今後レビューしない", style: .Cancel) {
      action in
      self.ud.setObject(true, forKey: "reviewed")
    }

    alertController.addAction(reviewAction)
    alertController.addAction(yetAction)
    alertController.addAction(neverAction)
    presentViewController(alertController, animated: true, completion: nil)
  }
}

평이한 해설


어디에나 있는 ViewController에 모두 놓으면 응용 프로그램 설명을 알리는 경보를 표시할 수 있습니다.
체크→앞으로 창 + Appstore 표시 안 함
아직 댓글이 없다→앞으로도 창이 나오지만 아무것도 하지 않으면 닫는다.
앞으로 검사하지 않음→앞으로 창구를 표시하지 않음.아무것도 안 하고 닫아.
※ ViewDid Apper가 아닙니다. ViewDid Load에 쓰면 오류가 발생합니다.

좋은 웹페이지 즐겨찾기