2017-06-21 59 views
1

我想要獲取背景並在iPhone應用程序中運行。試圖獲取工作背景

我希望應用程序通知用戶,通知已從服務器獲取新項目。

,並添加以下代碼的appDelegate &我有後臺模式功能檢查:

func application(_ application: UIApplication, didFinishLaunchingWithOptions 
       launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 

    UIApplication.shared.setMinimumBackgroundFetchInterval(30) 
    . 
    . 

}

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) ->()) 
{ 
    debugPrint("**** Fetch complete") 
} 

當我儘量減少程序我怎麼能得到它發送通知給用戶一個新的項目可用?我在上面丟失了什麼?

感謝

+0

iOS_有一個很不錯的[教程](https://www.raywenderlich.com/143128/background-modes-tutorial-getting-started)_Background Modes。您可以查看您的案例的___ Background Fetch___選項。 – nayem

+0

感謝你的理解,我得到了它的工作,有點,我可以讓我的應用程序執行一次獲取請求,但是,我無法獲取它每小時獲取一些數據。 – rubyist

回答

0

我假設你的服務器發送一個遠程通知到該設備,然後將設備做的事情有這樣一個項目變爲可用。在這種情況下,您需要做的就是安排一個本地通知立即觸發,並分別向用戶顯示通知。