iOS 註冊本地通知(推送)

2021-12-29 22:40:18 字數 2140 閱讀 3304

注:按home鍵讓app進入後台執行時,方可檢視通知。

- (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions {

// override point for customization after application launch.

// 註冊本地通知

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

if (localnotifit) {

// 獲取通知時間

nsdate *now = [nsdate date];

localnotifit.timezone = [nstimezone defaulttimezone];

// 10秒後開始通知

localnotifit.firedate = [now datebyaddingtimeinterval:10.0];

// 重複間隔 (下限為每分鐘通知一次)

localnotifit.repeatinterval = kcfcalendarunitminute;

// 提醒內容

localnotifit.alertbody = @十秒後手機將會**,趕快扔掉;

// 鎖屏狀態下,「滑動來」(這三個字是系統自動出現的)後面緊接著文字就是alertaction

localnotifit.alertaction = @解鎖(進入app);

// 通知欄裡的通知標題

localnotifit.alerttitle = @提示;

// 預設的通知聲音(只有在真機上才會聽到)

localnotifit.soundname = uilocalnotificationdefaultsoundname;

// 紅色圈圈數字

localnotifit.applicationiconbadgenumber = 1;

// 通知標識

nsmutabledictionary *dic = [nsmutabledictionary dictionarywithobject:@localnotificationid forkey:@key];

localnotifit.userinfo = dic;

// 將通知新增到系統中

[[uiapplication sharedapplication] schedulelocalnotification:localnotifit];

// 註冊通知(ios 8之後的註冊通知方法,ios 8以前暫不做介紹)

uiusernotificationsettings *settings = [uiusernotificationsettings settingsfortypes:uiusernotificationtypealert | uiusernotificationtypebadge | uiusernotificationtypesound categories:nil];www.2cto.com

[[uiapplication sharedapplication] registerusernotificationsettings:settings];

return yes;

// 接收到通知後觸發的方法,只有在app進入前台的時候才會執行。

-(void)application:(uiapplication *)application didreceivelocalnotification:(uilocalnotification *)notification

uialertview *alert = [[uialertview alloc] initwithtitle:@提示 message:@恭喜你上當了 delegate:nil cancelbuttontitle:nil otherbuttontitles:@我很開心, nil];

[uiapplication sharedapplication].applicationiconbadgenumber = 0;

[alert show];

// 取消通知

// [[uiapplication sharedapplication] cancelalllocalnotifications];

iOS 本地推送(本地通知)

設定本地通知 void registerlocalnotification nsinteger alerttime else 執行通知註冊 本地通知 函式,當應用程式在前台時呼叫 nslog noti notification 這裡真實需要處理互動的地方 獲取通知所帶的資料 nsstring not...

本地通知和推送通知 iOS開發

一 通知的型別 1.橫幅 banner 橫幅通知是在ios5中出現的新特性,是顯示在螢幕頂部的橫條,幾秒鐘後會自動消失。一條橫幅通知會顯示程式的小圖示 低分屏下顯示29 29的圖示,高分屏顯示58 58的圖示 程式的名字和通知的內容。小圖示可以幫助使用者一眼就看清楚是哪乙個應用程式在提醒他們。2.提...

iOS本地通知和遠端推送

本地通知 local notification 用於基於時間行為的通知。同時,如果程式不在前台執行,本地還是乙個有用的機制。比如,乙個應用程式在後台執行,向伺服器獲取訊息,當訊息到達時,通過本地通知機制通知使用者。本地通知uilocalnotification的例項,主要有三類屬性 1.schedu...