iOS 앱이 일시 중지 / 종료되고 사용자가 알림을 클릭 할 때 Firebase 푸시 알림을 처리하는 방법은 무엇입니까?

Nav Nav

내 앱이 일시 중지 / 종료되는 동안 어떤 기능을 다시 호출해야하는지 또는 알림을 받았는지 알고 싶습니다. 내 앱이 포 그라운드 / 백그라운드에있는 동안 처리 할 수 ​​있지만 앱이 종료되면 알림 페이로드를 처리하거나 구문 분석하는 방법과 위치가 확실하지 않습니다.

미테시

알림에서 열린 응용 프로그램에서 application : didFinishedLaunchingWithOptions 메서드가 호출되는 알림 데이터를 가져옵니다.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    if (launchOptions != nil)
    {
        // opened from a push notification when the app is closed
        NSDictionary* userInfo = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
        if (userInfo != nil)
        {
             NSLog(@"userInfo->%@", [userInfo objectForKey:@"aps"]);
        }
    }
    else
    {
        // opened app without a push notification.
    }
}

스위프트 5.1

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
    if launchOptions != nil {
        // opened from a push notification when the app is closed
        let userInfo = launchOptions?[.remoteNotification] as? [AnyHashable : Any]
        if userInfo != nil {
            if let object = userInfo?["aps"] {
                print("userInfo->\(object)")
            }
        }
    } else {
        // opened app without a push notification.
    }
}

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사