iOS10 推送必看 基礎篇

2022-05-30 22:00:14 字數 4218 閱讀 7119

一、簡單入門篇—看完就可以簡單適配完了

相對簡單的推送證書以及環境的問題,我就不在這裡講啦,我在這裡說的,是指原有工程的適配。

1.首先我們需要開啟下面的開關。所有的推送平台,不管是極光還是什麼的,要想收到推送,這個是必須開啟的喲~

之後,系統會生成乙個我們以前沒見過的檔案,如圖:

可能產生的問題:之前有朋友反饋過,將開發環境由 development 變成 production ,在開關這裡會產生錯誤,如圖:

如果大家點選fix issue之後,會驚奇的發現,aps environment由 production 又變成 development 了。

解決辦法:我的建議是不做任何修改。

經過我的測試,打包之後,生成的ipa包內,是沒有這個.entitlements 檔案的。經過測試,我發現是可以正常收到推送資訊的。測試的方法如下,大家也可以測試一下。

測試方法:打包之後安裝ipa檔案,然後利用極光推送,選擇生產環境,推送,即可。

經過上面的操作,你就會驚奇的發現,推送已經適配完畢了,ios10的系統,已經可以正常接收通知了。

二、中級篇

這裡我會給大家講一講ios10的推送,如何註冊,通過什麼**,哪些方法可以用,哪些方法不可以用。

1.系統自帶方法

大家不管是使用三方平台的推送,還是系統自帶的推送,都先應該了解下系統自帶方法,如何實現遠端通知的實現。

#ifdef nsfoundationversionnumber_ios_9_x_max

#import

#endif

if([[uidevicecurrentdevice].systemversion floatvalue]>= 10.0)];

}else

}];}elseif([[uidevicecurrentdevice].systemversion floatvalue]>8.0)elseif([[uidevicecurrentdevice].systemversion floatvalue]< 8.0)

// 註冊獲得device token

其中,獲得device token的方法是沒有改變的。

// 獲得device token

didregisterforremotenotificationswithdevicetoken:(nsdata *)devicetoken

else",body,title,subtitle,badge,sound,userinfo);

}completionhandler(unnotificationpresentationoptionbadge|unnotificationpresentationoptionsound|unnotificationpresentationoptionalert);// 需要執行這個方法,選擇是否提醒使用者,有badge、sound、alert三種型別可以設定

下面的**則是通知的點選事件:

// 通知的點選事件

- (void)usernotificationcenter:(unusernotificationcenter *)center didreceivenotificationresponse:(unnotificationresponse *)response withcompletionhandler:(void(^)())completionhandler

else",body,title,subtitle,badge,sound,userinfo);

}// warning: unusernotificationcenter delegate received call to -usernotificationcenter:didreceivenotificationresponse:withcompletionhandler: but the completion handler was never called.

completionhandler();// 系統要求執行這個方法

在點選事件中,如果我們不寫completionhandler()這個方法,可能會報一下的錯誤,希望大家注意下~

warning: unusernotificationcenter delegate received call to -usernotificationcenter:didreceivenotificationresponse:withcompletionhandler: but the completion handler was never called.

最後最後,我們要大家補充一下,舊版本的一些方法,方便大家擴充ios10的通知的通知,不影響原有邏輯。

didreceiveremotenotification:(nsdictionary *)userinfoelseif([[uidevice currentdevice].systemversion floatvalue]>= 8.0)else

註冊完成之後,我們則需要加入極光推送更新後,新加入的2個方法,這兩個方法在**方法中。

* @brief handle usernotifications.framework [willpresentnotification:withcompletionhandler:]

* @param center [unusernotificationcenter currentnotificationcenter] 新特性使用者通知中心

* @param notification 前台得到的的通知物件

* @param completionhandler 該callback中的options 請使用unnotificationpresentationoptions

- (void)jpushnotificationcenter:(unusernotificationcenter *)center willpresentnotification:(unnotification *)notification withcompletionhandler:(void(^)(nsinteger options))completionhandler;

* @brief handle usernotifications.framework [didreceivenotificationresponse:withcompletionhandler:]

* @param center [unusernotificationcenter currentnotificationcenter] 新特性使用者通知中心

* @param response 通知響應物件

* @param completionhandler

- (void)jpushnotificationcenter:(unusernotificationcenter *)center didreceivenotificationresponse:(unnotificationresponse *)response withcompletionhandler:(void(^)())completionhandler;

使用時,只需要在上面的**中新增極光的處理方法就可以了,具體使用如下圖:

if([response.notification.request.trigger iskindofclass:[unpushnotificationtrigger class]])

else",body,title,subtitle,badge,sound,userinfo);

}

unnotificationcontentextension – 通知內容擴充套件

unnotificationserviceextension- 通知服務擴充套件

unnotificationaction – 通知響應的方法

unerrorcode – 通知錯誤

unnotificationattachment – 附件通知

稍後我還會上傳demo路徑。

iOS開發 iOS10推送必看 基礎篇

ios10更新之後,推送也是做了一些小小的修改,下面我就給大家仔細說說。希望看完我的這篇文章,對大家有所幫助。一 簡單入門篇 看完就可以簡單適配完了相對簡單的推送證書以及環境的問題,我就不在這裡講啦,我在這裡說的,是指原有工程的適配。1.首先我們需要開啟下面的開關。所有的推送平台,不管是極光還是什麼...

ios10前台收到推送 iOS10推送通知開發教程

開始在xcode中啟用推送通知是很容易的,但你需要幾個步驟。建立乙個新的工程,給它起乙個唯一的bundle identifier.當您已經建立了project,去project settings頁選擇capabilities欄。開啟推送通知,如下所示。注意 如果你是蘋果的付費開發者成員,你就能看到推...

iOS10推送通知適配

ios10推送新增了usernotifications framework,使用起來其實很簡單。只是在ios10以上系統上點選通知欄,方法不再走原來的這兩個方法 而是在前台的時候 void usernotificationcenter unusernotificationcenter center ...