2017-01-18 5 views
1

버튼을 누르면 간단한 사용자 알림을 보내려고합니다. 인터넷에서 튜토리얼을 사용했는데, 여전히 작동하지 않습니다. 오류는 "스레드 1 : 신호 SIGABRT"입니다 여기에 코드 표준시 AppDelegate에사용자 알림 Swift 3

에 :

import UIKit 
import UserNotifications 

class Map: UIViewController, UNUserNotificationCenterDelegate { 

override func viewDidLoad() { 
    super.viewDidLoad() 

    //Senden von Mitteilungen? 
    let center = UNUserNotificationCenter.current() 
    center.requestAuthorization(options: [.alert, .sound]) { (granted, error) in 
    } 

    // Do any additional setup after loading the view. 
} 


@IBAction func Notification(_ sender: Any) { 

     //Set the content of the notification 
     let content = UNMutableNotificationContent() 
     content.title = "Achtung!" 
     content.subtitle = "Verbindung zum Beacon wurde getrennt" 
     content.body = "---" 

     //Set the trigger of the notification -- here a timer. 
     let trigger = UNTimeIntervalNotificationTrigger(
      timeInterval: 10.0, 
      repeats: false) 

     //Set the request for the notification from the above 
     let request = UNNotificationRequest(
      identifier: "10.second.message", 
      content: content, 
      trigger: trigger 
     ) 

     //Add the notification to the currnet notification center 
     UNUserNotificationCenter.current().add(
      request, withCompletionHandler: nil) 
    } 
} 

이 앱 위임입니다 :

import UIKit 
import Firebase 
import CoreLocation 
import UserNotifications 

@UIApplicationMain 
class AppDelegate: UIResponder, UIApplicationDelegate { 

    var window: UIWindow? 

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 

     FIRApp.configure() 

     return true 
    } 

    func applicationWillResignActive(_ application: UIApplication) { 
     // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 
     // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 
    } 

    func applicationDidEnterBackground(_ application: UIApplication) { 
     // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
     // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 
    } 

    func applicationWillEnterForeground(_ application: UIApplication) { 
     // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 
    } 

    func applicationDidBecomeActive(_ application: UIApplication) { 
     // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 
    } 

    func applicationWillTerminate(_ application: UIApplication) { 
     // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 
    } 


} 

//EXTENSIONS 

// Die Tastatur wird geschlossen, sobald der User außerhalb von ihr klickt 
extension UIViewController { 
    func hideKeyboardWhenTappedAround() { 
     let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(UIViewController.dismissKeyboard)) 
     view.addGestureRecognizer(tap) 
    } 

    func dismissKeyboard() { 
     view.endEditing(true) 
    } 
} 

나는 누군가가 내 실수를 알고 희망 :)

+0

자습서에 대한 링크를 제공 할 수 있습니까? – d00dle

+0

물론 : https://makeapppie.com/2016/08/08/how-to-make-local-notifications-in-ios-10/ – luki512

답변

0
  1. @IBAction 메서드의 이름을 다른 것으로 바꿉니다. 네임 스페이스 충돌이 있습니다.
  2. @IBAction이 실제로 단추에 연결되어 있고 해고 (메서드에 주석 또는 중단 점 추가)되어 있는지 확인하십시오.

편집 : 이동 당신의 FIRApp.configure() applicationDidFinishLaunchingWithOptions 중. 이것은 충돌을 일으키는 것으로 알려져 있습니다.

... 

override init() { 
    FIRApp.configure() 
} 

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 
    return true 
} 

... 

팁 : 소문자로 메소드 이름을 시작합니다. 대문자가있는 클래스. 이렇게하면 나중에 쉽게 확인할 수 있습니다.

+0

"알림"의 이름을 변경해야합니까? 이 작업을 수행하면 오류가 계속 표시됩니다. – luki512

+0

질문을 오류로 업데이트 할 수 있습니까? – d00dle

+0

그것은 : 스레드 1 : AppDelegate의 신호 SIGABRT – luki512

관련 문제