I am trying to create an app. I need to send a notification daily at a time the user decides I have used a date picker for the user to decide when they get the notification. I am also found a way to get it repeat but now I am having trouble assigning the date picker to the fire date. Please answer in swift. code:
import UIKit
class TechByteSchedulingViewController: UIViewController {
@IBOutlet weak var datePicker: UIDatePicker!
@IBAction func SavePressed(sender: UIButton) {
func sendNotification(sender: UIButton) {
var localNotification = UILocalNotification()
localNotification.fireDate = datePicker.date
localNotification.repeatInterval = .CalendarUnitDay
localNotification.alertBody = "check out your daily byte"
localNotification.timeZone = NSTimeZone.defaultTimeZone()
localNotification.applicationIconBadgeNumber = UIApplication.sharedApplication().applicationIconBadgeNumber + 1
localNotification.soundName = UILocalNotificationDefaultSoundName
UIApplication.sharedApplication().scheduleLocalNotification(localNotification)
}
func application(application: UIApplication, didReceiveLocalNotification notification: UILocalNotification) {
application.applicationIconBadgeNumber = 0
}
}
Here is the code from the app delegate class AppDelegate: UIResponder, UIApplicationDelegate is highlighted when I press done after setting the date picker
import UIKit
@UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
if(UIApplication.instancesRespondToSelector(Selector("registerUserNotificationSettings:"))) {
application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: .Alert | .Badge | .Sound, categories: nil))
var notification = UILocalNotification()
// play default sound
}
// Override point for customization after application launch.
return true }
Here is the errors in the console 2015-07-27 15:04:20.723 Daily Byte[3058:170905] Could not load the "second" image referenced from a nib in the bundle with identifier "NikhilKanamarlaDaily-Byte" 2015-07-27 15:04:20.723 Daily Byte[3058:170905] CUICatalog: Invalid asset name supplied: (null) 2015-07-27 15:04:20.723 Daily Byte[3058:170905] CUICatalog: Invalid asset name supplied: (null) 2015-07-27 15:04:20.724 Daily Byte[3058:170905] Could not load the "(null)" image referenced from a nib in the bundle with identifier "NikhilKanamarlaDaily-Byte" 2015-07-27 15:04:20.729 Daily Byte[3058:170905] CUICatalog: Invalid asset name supplied: (null) 2015-07-27 15:04:20.729 Daily Byte[3058:170905] CUICatalog: Invalid asset name supplied: (null) 2015-07-27 15:04:20.729 Daily Byte[3058:170905] Could not load the "(null)" image referenced from a nib in the bundle with identifier "NikhilKanamarlaDaily-Byte" 2015-07-27 15:04:20.729 Daily Byte[3058:170905] CUICatalog: Invalid asset name supplied: (null) 2015-07-27 15:04:20.729 Daily Byte[3058:170905] CUICatalog: Invalid asset name supplied: (null) 2015-07-27 15:04:20.729 Daily Byte[3058:170905] Could not load the "(null)" image referenced from a nib in the bundle with identifier "NikhilKanamarlaDaily-Byte" 2015-07-27 15:04:27.565 Daily Byte[3058:170905] -[Daily_Byte.TechByteSchedulingViewController DateChosen:]: unrecognized selector sent to instance 0x7fbd2a4bbef0 2015-07-27 15:04:27.589 Daily Byte[3058:170905] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Daily_Byte.TechByteSchedulingViewController DateChosen:]: unrecognized selector sent to instance 0x7fbd2a4bbef0' * First throw call stack: ( 0 CoreFoundation 0x0000000100ba7c65 exceptionPreprocess + 165 1 libobjc.A.dylib 0x0000000102712bb7 objc_exception_throw + 45 2 CoreFoundation 0x0000000100baf0ad -[NSObject(NSObject) doesNotRecognizeSelector:] + 205 3 CoreFoundation 0x0000000100b0513c ___forwarding_ + 988 4 CoreFoundation 0x0000000100b04cd8 _CF_forwarding_prep_0 + 120 5 UIKit 0x0000000101447d62 -[UIApplication sendAction:to:from:forEvent:] + 75 6 UIKit 0x000000010155950a -[UIControl _sendActionsForEvents:withEvent:] + 467 7 UIKit 0x00000001015588d9 -[UIControl touchesEnded:withEvent:] + 522 8 UIKit 0x0000000101494958 -[UIWindow _sendTouchesForEvent:] + 735 9 UIKit 0x0000000101495282 -[UIWindow sendEvent:] + 682 10 UIKit 0x000000010145b541 -[UIApplication sendEvent:] + 246 11 UIKit 0x0000000101468cdc _UIApplicationHandleEventFromQueueEvent + 18265 12 UIKit 0x000000010144359c _UIApplicationHandleEventQueue + 2066 13 CoreFoundation 0x0000000100adb431 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17 14 CoreFoundation 0x0000000100ad12fd __CFRunLoopDoSources0 + 269 15 CoreFoundation 0x0000000100ad0934 __CFRunLoopRun + 868 16 CoreFoundation 0x0000000100ad0366 CFRunLoopRunSpecific + 470 17 GraphicsServices 0x0000000104b7ba3e GSEventRunModal + 161 18 UIKit 0x00000001014468c0 UIApplicationMain + 1282 19 Daily Byte 0x000000010098cbf7 main + 135 20 libdyld.dylib 0x0000000102e48145 start + 1 21 ??? 0x0000000000000001 0x0 + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)