iOS本地通知

2021-09-11 13:14:15 字數 1954 閱讀 3708

眾所周知,ios中的通知推送分為:本地和遠端兩種。本地推送主要用於日曆鬧鐘等提醒類應用中,apns遠端推送以後專門寫一篇介紹,本文暫時按下不表。今天的主角是:uilocalnotification

#啟動通知

建立乙個本地通知:

//本地通知

uilocalnotification *localnoti = [[uilocalnotification alloc] init];

//時區

localnoti.timezone = [nstimezone defaulttimezone];

//觸發時間

localnoti.firedate = [nsdate datewithtimeintervalsincenow:10.0];

//重複間隔

localnoti.repeatinterval = kcfcalendarunitsecond;

//通知內容

localnoti.alertbody = @"歡迎來到英雄聯盟";

//通知聲音

localnoti.soundname = uilocalnotificationdefaultsoundname;

//通知徽標

//通知引數

localnoti.userinfo = [nsdictionary dictionarywithobject:@"傳遞資訊內容"

forkey:@"通知的key"];

//傳送通知:

複製**

//註冊通知:

uiusernotificationtype type = uiusernotificationtypealert | uiusernotificationtypebadge | uiusernotificationtypesound;

uiusernotificationsettings *settings = [uiusernotificationsettings settingsfortypes:type categories:nil];

}複製**

效果圖如下:

裡面:

uialertcontroller *alert = [uialertcontroller alertcontrollerwithtitle:@"本地通知" message:[notification.userinfo allvalues].firstobject preferredstyle:uialertcontrollerstylealert];

uialertaction *cacel = [uialertaction actionwithtitle:@"取消" style:uialertactionstylecancel handler:^(uialertaction * _nonnull action) ];

uialertaction *action = [uialertaction actionwithtitle:@"確認" style:uialertactionstyledefault handler:^(uialertaction * _nonnull action) ];

[alert addaction:cacel];

[alert addaction:action];

[self.window.rootviewcontroller presentviewcontroller:alert animated:yes completion:nil];

複製**

#取消通知

取消乙個本地通知:

// 獲取所有本地通知陣列

for (uilocalnotification *notification in

localnotifications) }}

複製**

#最後

demo_git位址

iOS本地通知

rt 本地通知 本地通知是uilocalnotification的例項,主要有三類屬性 對本地通知的數量限制,ios最多允許最近本地通知數量是64個,超過限制的本地通知將被ios忽略。如果就寫個簡單的定時提醒,是很簡單的,比如這樣 示例寫的很簡單,啟動應用後,就發出乙個定時通知,10秒後啟動。這時按...

iOS本地通知

本地通知由本應用負責呼叫,只能從當前裝置上得ios發出。本地通知適用於基於時間的程式,包括簡單的日曆程式或者to do列表型別的應用程式。本地通知是乙個uilocalnotification,它有如下屬性 每個應用程式最多只能傳送64個本地通知。如果系統發出通知時,應用程式處於前台執行,系統將會觸發...

ios本地通知

什麼時候需要推送跳轉 viewcontroller.m localnotification created by hq on 16 5 12.import viewcontroller.h inte ce viewcontroller ibaction sendnoty uibutton sende...