iOS推送(一) 本地推送

2021-07-22 20:12:12 字數 1181 閱讀 8568

以ios8.0和ios10.0兩個版本來建立乙個本地推送:

- (void)localpush

else ];

}}

推送建立完畢後,那麼我們便要考慮收到推送後會執行什麼樣的操作,這裡主要介紹處理接收到推送的地方。

首先我們要先註冊推送通知。8.0和10.0註冊推送還是很不一樣的。

// 8.0系統註冊推送

if ([[uidevice currentdevice].systemversion floatvalue] < 10.0) else

}];[[unusernotificationcenter currentnotificationcenter] getnotificationsettingswithcompletionhandler:^(unnotificationsettings * _nonnull settings) ];

}} return

yes;}

中設定一下**:

[unusernotificationcenter currentnotificationcenter].delegate = self

;

否則該**方法不會執行。

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

())completionhandler

ios8.0以後,如果程式在前台,收到推送會呼叫該方法:

ios10.0以後,如果程式在前台,收到推送會呼叫該方法:

- (void)usernotificationcenter:(unusernotificationcenter *)center willpresentnotification:(unnotification *)notification withcompletionhandler:(void (^)

(unnotificationpresentationoptions))completionhandler

iOS 10本地推送

ios 10本地推送 end ios 10 使用以下方法註冊,才能得到授權 center requestauthorizationwithoptions unauthorizationoptionalert unauthorizationoptionsound completionhandler b...

iOS裝置中的推送 四 本地推送 鬧鐘

推送的介紹 ios 裝置推送中除了遠端推送幾乎必不可少外,本地推送在一些情況下同樣有著其特殊的作用。本地推送最常用的就是在軟體中讓使用者自己設定乙個提醒,比如鬧鐘,備忘提醒等。今天我們就以乙個鬧鐘舉例來說明一下本地推送的應用。本地推送中屬性的介紹 uilocalnotification的例項,主要有...

iOS推送 實現本地推送

第一步 建立本地推送 建立乙個本地推送 uilocalnotification notification uilocalnotification alloc init autorelease 設定 10秒之後 nsdate pushdate nsdate datewithtimeintervalsi...