2017-05-19 7 views
0

방금 ​​swift로 내 첫 앱을 만들었습니다. 3. Firebase가 잘 작동하고 기기에서 알림을 수신하고 있습니다. 사용자가 알림을 클릭하면 작업을 설정합니다. 특정 제품 ID (백엔드에서 전송 된)로 특정 ProductViewController로 보내려합니다. 사용자가 로그인하지 않은 경우 ProductViewController에 로그인해야합니다.Firebase 푸시 알림 조치

AppDelegate.swift 코드 : 당신은 또한 당신의 스토리 보드를 통해 SEGUE을 설정해야 당신이 열려는의 ViewController의 식별자와 SEGUE을 발사 할 필요가

class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate, FIRMessagingDelegate { 

var window: UIWindow? 

func applicationReceivedRemoteMessage(_ remoteMessage: FIRMessagingRemoteMessage) { 
    print(remoteMessage.appData) 
} 

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

    // Override point for customization after application launch. 

    let lagFreeField = UITextField() 
    self.window?.addSubview(lagFreeField) 
    lagFreeField.becomeFirstResponder() 
    lagFreeField.resignFirstResponder() 
    lagFreeField.removeFromSuperview() 


    // [START register_for_notifications] 
    if #available(iOS 10.0, *) { 
     let authOptions : UNAuthorizationOptions = [.alert, .badge, .sound] 
     UNUserNotificationCenter.current().requestAuthorization(
      options: authOptions, completionHandler: {_,_ in }) 

     // For iOS 10 display notification (sent via APNS) 
     UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate 
     // For iOS 10 data message (sent via FCM) 
     FIRMessaging.messaging().remoteMessageDelegate = self as? FIRMessagingDelegate 

    } else { 
     let settings = UIUserNotificationSettings(types: [.alert, .badge , .sound], categories: nil) 

     application.registerUserNotificationSettings(settings) 
     application.registerForRemoteNotifications() 
    } 

    application.registerForRemoteNotifications() 

    // [END register_for_notifications] 

    FIRApp.configure() 

    print("AppDelegate") 

    IQKeyboardManager.sharedManager().enable = true 
    self.window = UIWindow(frame: UIScreen.main.bounds) 
    let storyboard = UIStoryboard(name: "Main", bundle: nil) 
    let tab = storyboard.instantiateViewController(withIdentifier: "TabBarController") as! UITabBarController 
    self.window?.rootViewController = tab 
    if Defaults.hasKey(.logged), let logged = Defaults[.logged], logged == true{ 
     APIRequest.username = Defaults[.username]! 
     APIRequest.password = Defaults[.password]! 
     let tab = storyboard.instantiateViewController(withIdentifier: "TabBarController") as! UITabBarController 
     self.window?.rootViewController = tab 

    } else { 
     let controller = storyboard.instantiateViewController(withIdentifier: "LoginViewController") 
     self.window?.rootViewController = controller 
    } 
    self.window?.makeKeyAndVisible() 

    return true 
} 

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) { 
    print("Userinfo \(userInfo)") 
} ... other default functions 

답변

0

..

self.performSegue(withIdentifier: "ProductViewControllerSegue",sender: nil) 

이것을 달성하기 위해서 ..

+0

나는 이것을 알고있다. 그러나 내가이 segue ..를 실행하기 위해 알림을 누를 때이 코드 라인을 어디에 추가 할 수 있는가? – DocPllana

+0

알림을 보낼 수 있습니다.이 행을 실행할 수있는 기본보기 컨트롤러에 작성된 함수에 notificationCenter를 사용하십시오. –