iOS 10 測試版推送通知的一個小坑

背景:

應(yīng)用收到推送通知后嘹履,通過 application:didReceiveRemoteNotification:fetchCompletionHandler: 方法,響應(yīng)推送通知的點擊渐排。測試發(fā)現(xiàn)在 iOS 10 上面雖然能收到推送,但是點擊通知中心的消息進(jìn)入應(yīng)用后赖临,應(yīng)用沒有跳轉(zhuǎn)到消息頁面鲤脏。

詳情:

調(diào)試時發(fā)現(xiàn),iOS 處理推送通知的方式在 iOS 9 和 iOS 10 上面有所不同厨姚。接收消息推送有兩個代理方法:

方法 1:application:didReceiveRemoteNotification:

方法 2:application:didReceiveRemoteNotification:fetchCompletionHandler:

當(dāng)同時實現(xiàn)方法兩個方法時衅澈,應(yīng)用在不同狀態(tài)下調(diào)用的方法不一致。

一般應(yīng)用有三種狀態(tài):

a)應(yīng)用未啟動谬墙;

b)應(yīng)用已啟動矾麻,但處于后臺纱耻;

c)應(yīng)用處于前臺。

對于以上三種狀態(tài)险耀,iOS 9 在收到消息通知后都會調(diào)用方法 2弄喘,這也符合官方文檔的描述。然而對于 iOS 10甩牺,當(dāng)應(yīng)用處于 a 或 b 狀態(tài)時蘑志,調(diào)用方法 1,當(dāng)應(yīng)用處于 c 狀態(tài)時贬派,調(diào)用方法 2急但。

然而官方文檔對于這兩個方法的描述,是這樣的:

Let’s review the possible scenarios that can arise when the system delivers a local notification or a remote notification for an app.

The notification is delivered when the app isn’t running in the foreground.In this case, the system presents the notification, displaying an alert, badging an icon, perhaps playing a sound, and perhaps displaying one or more action buttons for the user to tap.

The user taps a custom action button in an iOS 8 notification.In this case, iOS calls either?application:handleActionWithIdentifier:forRemoteNotification:completionHandler:or application:handleActionWithIdentifier:forLocalNotification:completionHandler:. In both methods, you get the identifier of the action so that you can determine which button the user tapped. You also get either the remote or local notification object, so that you can retrieve any information you need to handle the action.

The user taps the default button in the alert or taps (or clicks) the app icon.If the default action button is tapped (on a device running iOS), the system launches the app and the app calls its delegate’s?application:didFinishLaunchingWithOptions:method, passing in the notification payload (for remote notifications) or the local-notification object (for local notifications). Although application:didFinishLaunchingWithOptions:isn’t the best place to handle the notification, getting the payload at this point gives you the opportunity to start the update process before your handler method is called.

For remote notifications, the system also calls the?application:didReceiveRemoteNotification:fetchCompletionHandler:method of the app delegate.

If the app icon is clicked on a computer running OS X, the app calls the delegate’s?applicationDidFinishLaunching:method in which the delegate can obtain the remote-notification payload. If the app icon is tapped on a device running iOS, the app calls the same method, but furnishes no information about the notification.

The notification is delivered when the app is running in the foreground.The app calls the?application:didReceiveRemoteNotification:fetchCompletionHandler:or?application:didReceiveLocalNotification:method of the app delegate. (If application:didReceiveRemoteNotification:fetchCompletionHandler:isn’t implemented, the system calls application:didReceiveRemoteNotification:.) In OS X, the system calls?application:didReceiveRemoteNotification:

另外搞乏,在 方法 1 SDK的描述中波桩,蘋果是這么說的:

Implement the?application:didReceiveRemoteNotification:fetchCompletionHandler:method instead of this one whenever possible. If your delegate implements both methods, the app object calls the application:didReceiveRemoteNotification:fetchCompletionHandler: method.


結(jié)論:

目前 iOS 10 測試版的推送通知處理與文檔中描述的有出入,這可能是測試版的問題请敦,后續(xù)是否能夠更改未知镐躲,因此,目前最保險的方法就是侍筛,在 application:didFinishLaunchingWithOptions:?以及上述兩個方法中都檢測是否存在推送通知萤皂,并進(jìn)行處理。

測試使用的 iOS 10 版本為 10.0 (14A5335b)匣椰,測試手機(jī)為 iPhone 6裆熙,對于這個問題的其他相關(guān)描述:

1)http://www.heapoverflow.me/question-handeling-user-notifications-on-ios-10-38940193

2)http://www.openradar.me/27194349

問題還在跟進(jìn)中,隨時變更禽笑。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末入录,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子佳镜,更是在濱河造成了極大的恐慌纷跛,老刑警劉巖,帶你破解...
    沈念sama閱讀 221,820評論 6 515
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件邀杏,死亡現(xiàn)場離奇詭異贫奠,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)望蜡,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,648評論 3 399
  • 文/潘曉璐 我一進(jìn)店門唤崭,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人脖律,你說我怎么就攤上這事谢肾。” “怎么了小泉?”我有些...
    開封第一講書人閱讀 168,324評論 0 360
  • 文/不壞的土叔 我叫張陵芦疏,是天一觀的道長冕杠。 經(jīng)常有香客問我,道長酸茴,這世上最難降的妖魔是什么分预? 我笑而不...
    開封第一講書人閱讀 59,714評論 1 297
  • 正文 為了忘掉前任,我火速辦了婚禮薪捍,結(jié)果婚禮上笼痹,老公的妹妹穿的比我還像新娘。我一直安慰自己酪穿,他們只是感情好凳干,可當(dāng)我...
    茶點故事閱讀 68,724評論 6 397
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著被济,像睡著了一般救赐。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上只磷,一...
    開封第一講書人閱讀 52,328評論 1 310
  • 那天经磅,我揣著相機(jī)與錄音,去河邊找鬼喳瓣。 笑死,一個胖子當(dāng)著我的面吹牛赞别,可吹牛的內(nèi)容都是我干的畏陕。 我是一名探鬼主播,決...
    沈念sama閱讀 40,897評論 3 421
  • 文/蒼蘭香墨 我猛地睜開眼仿滔,長吁一口氣:“原來是場噩夢啊……” “哼惠毁!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起崎页,我...
    開封第一講書人閱讀 39,804評論 0 276
  • 序言:老撾萬榮一對情侶失蹤鞠绰,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后飒焦,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體蜈膨,經(jīng)...
    沈念sama閱讀 46,345評論 1 318
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 38,431評論 3 340
  • 正文 我和宋清朗相戀三年牺荠,在試婚紗的時候發(fā)現(xiàn)自己被綠了翁巍。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 40,561評論 1 352
  • 序言:一個原本活蹦亂跳的男人離奇死亡休雌,死狀恐怖灶壶,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情杈曲,我是刑警寧澤驰凛,帶...
    沈念sama閱讀 36,238評論 5 350
  • 正文 年R本政府宣布胸懈,位于F島的核電站,受9級特大地震影響恰响,放射性物質(zhì)發(fā)生泄漏趣钱。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,928評論 3 334
  • 文/蒙蒙 一渔隶、第九天 我趴在偏房一處隱蔽的房頂上張望羔挡。 院中可真熱鬧,春花似錦间唉、人聲如沸绞灼。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,417評論 0 24
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽低矮。三九已至,卻和暖如春被冒,著一層夾襖步出監(jiān)牢的瞬間军掂,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,528評論 1 272
  • 我被黑心中介騙來泰國打工昨悼, 沒想到剛下飛機(jī)就差點兒被人妖公主榨干…… 1. 我叫王不留蝗锥,地道東北人。 一個月前我還...
    沈念sama閱讀 48,983評論 3 376
  • 正文 我出身青樓率触,卻偏偏與公主長得像终议,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子葱蝗,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 45,573評論 2 359

推薦閱讀更多精彩內(nèi)容

  • PLEASE READ THE FOLLOWING APPLE DEVELOPER PROGRAM LICENSE...
    念念不忘的閱讀 13,491評論 5 6
  • 調(diào)試時發(fā)現(xiàn)穴张,iOS 處理推送通知的方式在 iOS 9 和 iOS 10 上面有所不同。接收消息推送有兩個代理方法:...
    zinder閱讀 194評論 0 1
  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理两曼,服務(wù)發(fā)現(xiàn)皂甘,斷路器,智...
    卡卡羅2017閱讀 134,702評論 18 139
  • 系統(tǒng) API :iOS < 7悼凑、 7 <= iOS < 10偿枕、 iOS >= 10app 狀態(tài):后臺運(yùn)行、 前臺...
    頭像是我老婆閱讀 1,744評論 0 1
  • 【零組件篇】 再把需要的器件列下來較為詳講一下户辫,每一部分對于新老手的都是一門大學(xué)問益老,切記不可心急,慢慢體會寸莫。下面會...
    康雙全閱讀 1,021評論 0 4