2016-06-15 2 views
1

응용 프로그램이 종료 된 후 응용 프로그램이 알림 본문에서 시작되면 팝업을 열려고합니다. 나는 AppDelegate에서 그것을하고 싶어한다. LocalNotifications을 사용하고 있습니다. 작업 버튼을 사용하면 특정보기를 여는 방법을 알고 있지만 알림 본문을 클릭하면 내용을 여는 방법을 알지 못합니다.응용 프로그램이 종료 된 후 알림 본문에서 응용 프로그램이 시작되면 팝업을 엽니 다.

편집 : 내 솔루션은 앱이 종료되지 않은 경우에만 작동합니다.

Edit2가 :는 그것이 내가 코드에서 viewController을 열하려고 편의상

? : 할 수있는 올바른 방법인가 실제로 나는 그것을 위해 내가 JSSAlertView

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 
// Override point for customization after application launch. 



    if let TappedNotification = launchOptions?[UIApplicationLaunchOptionsLocalNotificationKey] as? NSDictionary { 

     print("The notification is \(TappedNotification)") 
     let mainStoryboardIpad : UIStoryboard = UIStoryboard(name: "Main", bundle: nil) 
     let initialViewControlleripad : UIViewController = mainStoryboardIpad.instantiateViewControllerWithIdentifier("Main") as UIViewController 
     self.window = UIWindow(frame: UIScreen.mainScreen().bounds) 
     self.window?.rootViewController = initialViewControlleripad 
     self.window?.makeKeyAndVisible() 

    } 
} 





return true 
를 사용하고, 경고 메시지가 필요합니다

}

어떤 상태의 앱인지 감지하려고했지만 앱이 종료되고 알림에서 열면 테스트 할 수 없습니다.

if application.applicationState == UIApplicationState.Active { 
    print("App already open") 

} else { 
    print("App opened from Notification") 
} 

나는 else{이 점을 추가하려고하지만 특정보기를 열 수 없습니다 :

하자 mainStoryboardIpad : UIStoryboard = UIStoryboard (이름 : "메인", 번들 : 전무)

let mainStoryboardIpad : UIStoryboard = UIStoryboard(name: "Main", bundle: nil) 
let initialViewControlleripad : UIViewController = mainStoryboardIpad.instantiateViewControllerWithIdentifier("Main") as UIViewController 
self.window = UIWindow(frame: UIScreen.mainScreen().bounds) 
self.window?.rootViewController = initialViewControlleripad 
self.window?.makeKeyAndVisible() 

I을 알림 본문을 클릭하면 Twitter 또는 Instagram과 같은 효과를 원합니다. 하지만 제 경우에는 popover (모달)을 원합니다.

답변

1

앱 종료되고 당신은 통지를 얻을하고 다음 코드를 따라하고 didFinishLaunchingWithOptions 방법으로 코드를 작성해야한다는 것을이 정보를 얻을 알림을 누릅니다 경우 : 앱이 아닌 경우

if let TappedNotification = launchOptions?[UIApplicationLaunchOptionsRemoteNotificationKey] as? NSDictionary { 

     print("The notification is \(TappedNotification)") 
     let mainStoryboardIpad : UIStoryboard = UIStoryboard(name: "Main", bundle: nil) 
     let initialViewControlleripad : UIViewController = mainStoryboardIpad.instantiateViewControllerWithIdentifier("Main") as UIViewController 
     self.window = UIWindow(frame: UIScreen.mainScreen().bounds) 
     self.window?.rootViewController = initialViewControlleripad 
     self.window?.makeKeyAndVisible() 

    } 

백그라운드 모드 나 액티브 모드에서는 알림 용으로 특정 루트 뷰 컨트롤러를 설정합니다. 알림보기 컨트롤러에서 돌아 오면 응용 프로그램 흐름에 따라 rootview 컨트롤러를 변경해야합니다.

검토 한 결과, 나는 다음과 같이 변경과 수정 샘플 코드 :

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 
     // Override point for customization after application launch. 
     self.window = UIWindow(frame: UIScreen.mainScreen().bounds) 
     let tintColor = UIColor(red: 252/255, green: 72/255, blue: 49/255, alpha: 1) 
     window!.tintColor = tintColor 

     application.registerForRemoteNotifications() 
     application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: .Alert , categories: nil)) 


     let notification = launchOptions?[UIApplicationLaunchOptionsLocalNotificationKey] as! UILocalNotification! 
     if (notification != nil) { 
            print("The notification is \(notification)") 

        let mainStoryboardIpad : UIStoryboard = UIStoryboard(name: "Main", bundle: nil) 
        let initialViewControlleripad : UIViewController = mainStoryboardIpad.instantiateViewControllerWithIdentifier("Main") as! NotificationViewController 

        self.window?.rootViewController = initialViewControlleripad 
        self.window?.makeKeyAndVisible() 


        let alert = UIAlertController(title: "Alert", message: "YES NOTIFICITO", preferredStyle: UIAlertControllerStyle.Alert) 
        alert.addAction(UIAlertAction(title: "Click", style: UIAlertActionStyle.Default, handler: nil)) 
        window!.rootViewController?.presentViewController(alert, animated: true, completion: nil) 
        return true 


     }else{ 

      let mainStoryboardIpad : UIStoryboard = UIStoryboard(name: "Main", bundle: nil) 
      let initialViewControlleripad : UIViewController = mainStoryboardIpad.instantiateViewControllerWithIdentifier("first") as UIViewController 
      self.window?.rootViewController = initialViewControlleripad 
      self.window?.makeKeyAndVisible() 

      let alert = UIAlertController(title: "Alert", message: "NO NOTIFICIATION", preferredStyle: UIAlertControllerStyle.Alert) 
      alert.addAction(UIAlertAction(title: "Click", style: UIAlertActionStyle.Default, handler: nil)) 
      window!.rootViewController?.presentViewController(alert, animated: true, completion: nil) 
      return true 
     } 

    } 
+0

@So 난 당신이 내 코드는 지금 작동해야 올바른 이해합니다. 하지만 작동하지 않습니다. 내 편집을 확인하십시오. 맞습니까? –

+0

application.applicationState == UIApplicationState.Active {if UIApplicationLaunchOptionsRemoteNotificationKey –

+0

} 내가 없으면 시도했지만 여전히 작동하지 않는지 확인할 필요가 없습니다. 오 기다려. 내 초기 viewcotroller를 "Main"으로 설정해야합니까? 실제로는 초기 ATM이 아니기 때문입니다. –