-1

I have made one sample application which fires local notification.

When notification fires it always shows banner in notification area in device, which I have shown in image.enter image description here

But I want alert rather than this and want to perform action based upon selected option from that alert.

Code to fire local notification is given as below.

-(IBAction)setNotification:(id)sender{

UILocalNotification *localNotif = [[UILocalNotification alloc] init];
if (localNotif == nil)
{
    return;
}

localNotif.timeZone = [NSTimeZone defaultTimeZone];

// Get the year, month, day from the date
NSDateComponents *components = [[NSCalendar currentCalendar] components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit|NSTimeZoneCalendarUnit|NSSecondCalendarUnit|NSHourCalendarUnit|NSMinuteCalendarUnit fromDate:[NSDate date]];

// Set the second to be zero
components.minute = components.minute + 1;
components.second = 0;

// Create the date
NSDate *date = [[NSCalendar currentCalendar] dateFromComponents:components];
NSLog(@"Fire Date :: %@",date);
localNotif.fireDate = date;

localNotif.alertBody = [NSString stringWithFormat:@"First Alarm"];


localNotif.alertAction =@"Ok";

localNotif.soundName=@"Alarm_1.mp3";

localNotif.applicationIconBadgeNumber = 1;


localNotif.alertAction = @"Application name";
localNotif.HasAction = true;

// Schedule the notification
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];

}

Can any body please tell me if there is any mistake.

Thanks in advance.

Jayeshkumar Sojitra
  • 2,501
  • 4
  • 31
  • 44

3 Answers3

0

Change the Type of Notification in Setting -> Notification Centre - > Your App -> Alert:

enter image description here

Originally from Quinn "The Eskimo!", as quoted by IBG:

"This depends on you mean. You have some control over how the notification appears based on how you set the UILocalNotification properties (things like alertBody, soundName, and so on). However, if you're asking about the way in which those properties are interpreted (the things the user can customise in Settings > Notifications), those are user preferences and not exposed via any API."

Community
  • 1
  • 1
user1673099
  • 3,293
  • 7
  • 26
  • 57
0

Here is a quick and short answer. You cannot do that. Apples documentation only states didReceiveLocalNotification. The way the notification is shown is not up to the developer. The user will choose how he wants to see notification using SETTINGS.

In your case, just wire up logic by implementing the delegate callback when the user taps on the notification.

Legolas
  • 12,145
  • 12
  • 79
  • 132
-1

You can get your notification in this method:

  • (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo

write this code for fetch the data from userInfo:

[[userInfo objectForKey:@"aps"] objectForKey:@"price"]];

use userInfo Dict to get The notification Value and after that you can use that data for Alert.

Deep Gami
  • 508
  • 3
  • 13