ios 本地推送

2021-07-23 15:05:08 字數 1569 閱讀 7689

首先建立乙個單例,繼承與nsobject

在.h中

//建立推送

-(void) addnotifiction:(nsstring*) firedate keya:(nsstring*)key messagea:(nsstring*)message;

//移除對應的推送

-(void)removelocalnotificationbykey:(nsstring*)key;

//移除所有推送

-(void)removelocalallnotification;

註冊推送

+(notificationhelper*) shareinstance;

在.m中

static notificationhelper* instance;

+(notificationhelper*) shareinstance

); return instance ;

}#endif

}-(void) addnotifiction:(nsstring*) firedate keya:(nsstring*)key messagea:(nsstring*)message

localnotification.firedate = now;

//設定 時區

localnotification.timezone = [nstimezone defaulttimezone];

// 觸發後,彈出警告框中顯示的內容

localnotification.alertbody = message;

localnotification.alertaction = nslocalizedstring(@"view details", nil);

// 觸發時的聲音(這裡選擇的系統預設聲音)

localnotification.soundname = uilocalnotificationdefaultsoundname;

// 觸發頻率(repeatinterval是乙個列舉值,可以選擇每分、每小時、每天、每年等)

localnotification.repeatinterval = kcfcalendarunitminute;//測試用暫時寫死為每隔一天 0:不重複

// 設定通知的id,可用於通知移除,也可以傳遞其他值,當通知觸發時可以獲取

localnotification.userinfo = @;

// 註冊本地通知 }

- (void)removelocalnotificationbykey:(nsstring*)key

}}- (void)removelocalallnotification

在你需要推送的地方寫下以下**

[[notificationhelper shareinstance] addnotifiction:timestring keya:@"key" messagea:@"可以領取體力了!" ];

然後你的本地推送就寫完了 ,是不是很簡單啊

ios本地推送

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

iOS 本地推送

通知完一定要取消,ios最多允許最近本地通知數量是64個,超過限制的本地通知將被忽略。第一步 建立本地推送 建立乙個本地推送 uilocalnotification notification uilocalnotification alloc init autorelease 設定10秒之後 nsd...

iOS本地推送

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