2014-10-29 3 views
8

, 당신은 다음과 같은 방법을 얻을 :launchOptions 처리 방법 : [NSObject : AnyObject]? 스위프트에서? 신속한 AppDelegate에 클래스에서

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 
    // ...code... 
    return true 
} 

launchOptions: [NSObject: AnyObject]? 매개 변수는 선택 사항입니다. Objective-C에서는 NSDictionary으로 전달됩니다. 그것으로부터 UIApplicationLaunchOptionsRemoteNotificationKey을 추출하려고합니다. Objective-C에서의 작업 방법은 다음과 같습니다.

NSDictionary *remoteNotification = launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey]; 

if (remoteNotification) 
{ 
    // ...do stuff... 
} 

Swift에서 어떻게 할 것입니까?

답변

27

스위프트, 당신은 이런 식으로 할 거라고 :

if let remoteNotification = launchOptions?[UIApplicationLaunchOptionsRemoteNotificationKey] as? NSDictionary { 
    // ...do stuff... 
} 
+1

remoteNotification에 포함 된 내용을 화면에 어떻게 기록 할 수 있습니까? 앱이 xcode에 연결되어있는 동안 푸시 알림에서 시작해야하기 때문에? –

+0

실제로 일어나는 일을 확인하는 가장 좋은 방법은 UIAlertView를 메시지와 함께 출력하고, 그렇지 않으면 기록 할 print 문 내용으로 던지는 것입니다. –

1

을 나는이 같은 스위프트에 그것을 처리 :

내가 스위프트 3 생각
if let remoteNotification = launchOptions?[UIApplicationLaunchOptionsRemoteNotificationKey] as? [NSObject : AnyObject] { 
    // ... do stuff 
} 
0

, 그것은 다음과 같이 될 것이다 :

if (launchOptions?[UIApplicationLaunchOptionsKey.remoteNotification] as? NSDictionary) != nil { 
    // ...do stuff   
}