2016-12-04 44 views
0

在iOS中,一旦在鎖定屏幕上收到通知,我需要在我的應用程序中啓動後臺服務。啓用iOS通知以激活後臺服務

我知道這可以發生在Android,但這是可能的iOS內?

+0

什麼是「後臺服務」? – matt

+0

@matt他可能指的是在收到遠程通知時啓動的後臺任務。 –

+0

例如,如果發送了推送通知,我的應用程序的一部分將啓動@ @AlejandroIván,正確 – Sauron

回答

1

如果用戶點擊通知警報,您的應用程序會在後臺發送一個事件,並且現在正在後臺運行(甚至可能需要這意味着您的應用程序已被移到前臺)。

+0

有關於通知的WWDC 2016視頻,這些視頻已經針對iOS 10進行了大量修改。我會推薦觀看它們。 – matt

1

iOS中不存在與Android服務相當的功能。

推送有兩種類型,一種發送到應用程序,另一種發送給用戶。

If a push is sent to the user then: 
- if your app is terminated, the push is displayed to the user 
- if your app is in the background, the push is displayed to the user 
- if your app is in the foreground, the push is delivered to the app. 
If a push is sent to the app then: 
- if your app is terminated, the push goes nowhere 
- if your app is in the background, the push is sent to the app, and you *may* be able to perform some activity at that point, depending upon your background modes. 
- if your app is in the foreground, the push is sent to the app. 

(除此之外,在iOS的10,推壓導向用戶可以截獲和它們顯示給用戶之前,它們的內容發生變化。但是,他們不會被你的應用程序截獲,它們被截獲這是而不是這意味着你的應用程序可以運行在這一點。)

所以你的問題的答案是否定的,因爲服務不存在。如果您可以在發送應用程序推送時在後臺運行,那麼只有當應用程序未終止並且您具有某些後臺功能時纔會這樣做。 由於終止因素,因此它不是您可以依賴的機制。