我正在通過收集365個英語「sayings」來創建應用程序。在我的應用程序中,我想使用本地通知(每天從我的應用程序發出的言論應通知給用戶)。我想使用本地通知,而不是推送notification.is有可能每天(365天)通知用戶不同的說法。可以任何人請幫助我.....如何在iOS中創建365天的本地通知
回答
有沒有辦法創建365個不同的本地通知。 根據documentation本地通知限於64個預定的本地通知。
但是,當用戶啓動您的應用程序時,您可以更新通知。 如果通知的內容是一樣的,你也可以安排與365個字典一個recurring basis
是你can.Just創建陣列交付通知。字典鍵應該是id和說。
UILocalNotification *localNotif = [[UILocalNotification alloc]init];
NSCalendar *calendar = [NSCalendar currentCalendar];
NSDate *datePickerDate = [NSDate date];
NSDateComponents *dateComponents = [calendar components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit) fromDate:datePickerDate];
NSDateComponents *timeComponents = [calendar components:(NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit) fromDate:datePickerDate];
NSDateComponents *dateComps = [[NSDateComponents alloc]init];
[dateComps setYear:[dateComponents year]];
[dateComps setMonth:[dateComponents month]];
[dateComps setDay:[dateComponents day] + 1];
[dateComps setHour:[timeComponents hour] ];
[dateComps setMinute:[timeComponents minute]];
[dateComps setSecond:00];
NSDate *fireDate = [calendar dateFromComponents:dateComps];
//NSLog(@"%@",fireDate);
localNotif.fireDate = fireDate;
localNotif.soundName = UILocalNotificationDefaultSoundName;
localNotif.alertAction = @"Alarm";
localNotif.repeatInterval = NSDayCalendarUnit;
localNotif.userInfo = [NSDictionary dictionaryWithObjectsAndKeys:@"1",@"id", nil];
localNotif.alertBody = [saying with id 1];//you can use predicate here
[[UIApplication sharedApplication]scheduleLocalNotification:localNotif];
在應用程序委託
,
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
int i = [[localNotif.userInfo objectForKey:@"id"] intValue] + 1;
localNotif.alertBody = [saying in index i ];
[localNotif.userInfo setValue:i forKey:@"id"];
}
你的代碼有很多問題,首先你只能註冊64個通知,Seconde的'application:didReceiveLocalNotification:'只會觸發你的應用程序在觸發通知時運行。 – rckoenes
@rckoenes:謝謝你的評論。實際上它不是365通知。每天只有一個重複間隔的通知。 2.你是對的。應用程序:didReceiveLocalNotification:僅在用戶收到它時調用。但這是唯一的可能性。否則你怎麼能做到這一點? – manujmv
那麼這是問題的關鍵。只有64個註冊通知。您也可以通過檢查選項是否包含本地通知來檢查應用程序是否以'application:didFinishLaunchingWithOptions:'中的本地通知開始。一種可以使其工作的方式是在每次啓動應用程序時註冊64通知,這樣應用程序將始終在上次啓動後的63天內運行。但再次不是100%可靠。 – rckoenes
- 1. 創建iOS本地通知
- 2. 在http請求中創建xamarin ios的本地通知
- 3. 如何在ios每天同時發佈隨機本地通知
- 4. 如何創建多個本地通知
- 5. 如何重複本地通知後的iOS 814天和9
- 6. 如何在一週中的特定幾天重複本地通知(iOS Swift 3)
- 7. 如何在xcode中創建本地通知?
- 8. 如何在iPhone應用程序中創建本地通知
- 9. 如何在Swift 3中創建/註冊本地通知設置?
- 10. 本地通知未在iOS中清除
- 11. 如何在7天的暫停中設置21天的UI本地通知
- 12. 在iOS中創建持久通知
- 13. 如何在通知Android中創建天文臺?
- 14. 使用react-native創建本地推送通知 - IOS
- 15. IOS重寫本地通知
- 16. IOS本地推送通知
- 17. 無聲本地通知IOS
- 18. 持續本地通知iOS
- 19. iOS本地通知背景
- 20. ios本地通知didreceivelocalnotification
- 21. iOS和本地通知
- 22. 本地通知iOS 8
- 23. 本地通知iOS 5
- 24. iOS通知本地化?
- 25. ios取消本地通知
- 26. 本地通知phonegap ios
- 27. 如何在不同的時間每天重複本地通知
- 28. iOS創建推送通知
- 29. 推遲iOS中的本地通知10
- 30. iOS中的多個本地通知
只能設置64 ['UILocalNotifications'](http://developer.apple.com/library/ios/#documentation/iPhone/Reference/UILocalNotification_Class /Reference/Reference.html)爲你的應用程序。 – rckoenes
這是Apple的官方教程:http://developer.apple.com/library/ios/#DOCUMENTATION/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/IPhoneOSClientImp.html#//apple_ref/doc/uid/TP40008194-CH103-SW13 – Raptor
查看Adi鏈接中提到的教程,邏輯將保存說明到數據庫中,並在每次通知被觸發時選擇一個新的說法。最簡單的方法是使用索引作爲從數據庫中讀取的年份。 –