Reputation: 31
I am relatively new to Xcode, I am building a very simple alarm clock and below is a small snippet of the app. My question is: how to display a custom view ( i.e. a picture or an animation ) when the alarm is fired, and put also a " dismiss " button on it ? Thank you in advance
Nicola
- (void) scheduleLocalNotificationWithDate:(NSDate *)fireDate :(NSString *)message
{
UILocalNotification *notificaiton = [[UILocalNotification alloc] init];
if (notificaiton == nil)
return;
notificaiton.fireDate = fireDate;
notificaiton.alertBody = message;
notificaiton.timeZone = [NSTimeZone defaultTimeZone];
notificaiton.alertAction = @"View";
notificaiton.soundName = @"alarm-clock-1.mp3";
notificaiton.applicationIconBadgeNumber = 1;
notificaiton.repeatInterval = kCFCalendarUnitWeekday;
NSLog(@"repeat interval is %@",notificaiton.description);
[[UIApplication sharedApplication] scheduleLocalNotification:notificaiton];
Upvotes: 2
Views: 1442
Reputation:
If your app is in background you can use Kalpesh suggested. But You cannot show a custom view directly if you have application in foreground. You can show an alert or customized alert and then once you accepts that alert and then show the custom view.
Upvotes: 0
Reputation: 5334
Use this method
Handle the notificaton when the app is running
- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif
{
// show your custom alert view
}
Handle launching from a notification
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UILocalNotification *localNotif =
[launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (localNotif)
{
// show your custom alert view
}
return YES;
}
Upvotes: 1