ios如何實現本地推送,相容ios8

2022-08-31 13:03:09 字數 3061 閱讀 3682

如果要相容ios8在ios中實現本地推送,關鍵是要注意:ios8在實現本地推送時需要通過如下語句進行註冊。

}在notificationhelper.m檔案中實現方法如下:

#import "notificationhelper.h"@implementation notificationhelper

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是乙個列舉值,可以選擇每分、每小時、每天、每年等)

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

localnotification.userinfo = @;

// 註冊本地通知

[localnotification release];

}

/**

removelocalnotificationbykey

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

}}- (void)removelocalallnotification

@end

用法舉例:

比如在應用啟動的時候調在didfinishlaunchingwithoptions方法中呼叫:

進行註冊和版本控制,在需要傳送通知的時候呼叫:

[[notificationhelper shareinstance] addnotifiction:"18:30:30" keya:"key" messagea:"可以領取體力了!" ]

完畢。由於公司的手遊專案需要使用到本地推送,而我們的專案是用quick cocos2d-x引擎,前端使用lua編寫指令碼和介面。這樣就面臨乙個問題:如何編寫友好的介面讓lua能夠呼叫oc來實現推送,這樣的話所有的邏輯都在lua中實現。

如果要相容ios8在ios中實現本地推送,關鍵是要注意:ios8在實現本地推送時需要通過如下語句進行註冊。

}在notificationhelper.m檔案中實現方法如下:

#import "notificationhelper.h"@implementation notificationhelper

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是乙個列舉值,可以選擇每分、每小時、每天、每年等)

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

localnotification.userinfo = @;

// 註冊本地通知

[localnotification release];

}

/**

removelocalnotificationbykey

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

}}- (void)removelocalallnotification

@end

用法舉例:

比如在應用啟動的時候調在didfinishlaunchingwithoptions方法中呼叫:

進行註冊和版本控制,在需要傳送通知的時候呼叫:

[[notificationhelper shareinstance] addnotifiction:"18:30:30" keya:"key" messagea:"可以領取體力了!" ]

完畢。由於公司的手遊專案需要使用到本地推送,而我們的專案是用quick cocos2d-x引擎,前端使用lua編寫指令碼和介面。這樣就面臨乙個問題:如何編寫友好的介面讓lua能夠呼叫oc來實現推送,這樣的話所有的邏輯都在lua中實現。

iOS推送 實現本地推送

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

iOS推送 實現本地推送

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

iOS本地推送實現過程

第二步 實現乙個推送訊息 void localpush nslog notification.alertbody 減少角標的顯示個數 如何解除本地通知 獲取本地推送陣列 宣告本地通知物件 uilocalnotification localnotification if localarray loca...