首页 > 解决方案 > 如何检测到 watchOS 应用程序已终止?

问题描述

我正在编写将由 watchOS 应用程序使用的 SDK。我需要像图像一样捕捉应用程序关闭的那一刻。甚至当应用程序从非运行状态变为活动状态时。现在我只能捕捉从非活动到活动的过渡。

我已经尝试过这个:

_applicationWillEnterForegroundObserver = [notificationCenter addObserverForName:@"UIApplicationWillEnterForegroundNotification" object:NULL queue:NULL usingBlock:^(NSNotification * _Nonnull note) {
        [self willEnterForeground];
    }];
    _applicationDidBecomeActiveObserver = [notificationCenter addObserverForName: @"UIApplicationDidBecomeActiveNotification" object:NULL queue:NULL usingBlock:^(NSNotification * _Nonnull note) {
        [self didBecomeActive];
    }];
    [notificationCenter addObserverForName:@"UIApplicationWillTerminateNotification" object:NULL queue:NULL usingBlock:^(NSNotification * _Nonnull note) {
        [self willTerminate];
    }];
    _applicationWillResignActiveObserver = [notificationCenter addObserverForName:@"UIApplicationWillResignActiveNotification" object:NULL queue:NULL usingBlock:^(NSNotification * _Nonnull note) {
        [self willResignActive];
    }];

WillTerminate 通知根本不起作用。:( 我怎样才能做到这一点?

在此处输入图像描述

标签: objective-cwatchos

解决方案


推荐阅读