2017-01-03 5 views
0

iOS 및 Swift를 처음 사용합니다. 내 응용 프로그램에서 원격 알림을 구현하고 있습니다. 앱이 활성화되어 있거나 백그라운드에서 작동하면 모든 것이 잘 작동합니다. 하지만 앱이 종료 될 때 알림이 표시되지 않습니다. 내가받는 것은 알림의 알림 소리뿐입니다. 응용 프로그램은 사망 상태에있을 때앱 종료시 원격 알림

didFinishLaunchingWithOptions 

그래서 당신이 여기에서 제대로 처리해야 당신이 알림을 수신하고 응용 프로그램이 사망 상태 인 경우 AppDelegate에 방법 아래

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) { 
    if #available(iOS 10.0, *){ 
    }else{ 
     let notification = UILocalNotification() 
     notification.alertTitle = "my Title" 
     notification.alertBody = "My Message" 
     notification.category = "customCategory" 
     notification.soundName = UILocalNotificationDefaultSoundName 
     application.scheduleLocalNotification(notification) 
    } 
} 

답변

-1

가 호출됩니다. 코드 아래

는 didFinishLaunchingWithOptions 방식의 원격/푸시 또는 로컬 통지를 식별하는 데 도움이 :

if let launchOpts = launchOptions as [UIApplicationLaunchOptionsKey: Any]? { 
      if let notificationPayload = launchOpts[UIApplicationLaunchOptionsKey.remoteNotification] as? NSDictionary { 

       //Handle push notification here 
       } 
else if let notification = (launchOpts as NSDictionary).object(forKey: "UIApplicationLaunchOptionsLocalNotificationKey") as? UILocalNotification { 
       //Handle local notification here 
       } 
+0

당신이 날 일부 예에 제안 할 수 있습니다? 응용 프로그램이 시작될 때 didFinishLaunchingWithOptions 메서드가 호출됩니다. 응용 프로그램이 실행되고 있지 않을 때 알림을 표시하는 방법은 무엇입니까? –