第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

應(yīng)用未運行時的Healthkit后臺傳遞

應(yīng)用未運行時的Healthkit后臺傳遞

白豬掌柜的 2019-11-28 13:46:33
如果HealthKit后臺交付未運行,是否可以啟動該應(yīng)用程序?特別是在終止狀態(tài)下?
查看完整描述

3 回答

?
鳳凰求蠱

TA貢獻1825條經(jīng)驗 獲得超4個贊

在iOS 8.1中可以。不過,您需要確保在應(yīng)用程序委托的中重新創(chuàng)建觀察者查詢application:didFinishLaunchingWithOptions:。8.0中的錯誤完全阻止了HealthKit的后臺通知。


編輯:


在您的AppDelegate中:


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    //create/get your HKHealthStore instance (called healthStore here)

    //get permission to read the data types you need.

    //define type, frequency, and predicate (called type, frequency, and predicate here, appropriately)


    UIBackgroundTaskIdentifier __block taskID = [application beginBackgroundTaskWithExpirationHandler:^{

        if (taskID != UIBackgroundTaskInvalid) {

            [application endBackgroundTask:taskID];

            taskID = UIBackgroundTaskInvalid;

        }

    }];

    [healthStore enableBackgroundDeliveryForType:type frequency:frequency withCompletion:^(BOOL success, NSError *error) {}];

    HKQuery *query = [[HKObserverQuery alloc] initWithSampleType:healthType predicate:predicate updateHandler:

        ^void(HKObserverQuery *query, HKObserverQueryCompletionHandler completionHandler, NSError *error)

        {

            //If we don't call the completion handler right away, Apple gets mad. They'll try sending us the same notification here 3 times on a back-off algorithm.  The preferred method is we just call the completion handler.  Makes me wonder why they even HAVE a completionHandler if we're expected to just call it right away...

            if (completionHandler) {

                completionHandler();

            }

            //HANDLE DATA HERE

            if (taskID != UIBackgroundTaskInvalid) {

                [application endBackgroundTask:taskID];

                taskID = UIBackgroundTaskInvalid;

            }

        }];

    [healthStore executeQuery:query];

}


查看完整回答
反對 回復(fù) 2019-11-28
  • 3 回答
  • 0 關(guān)注
  • 928 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號