0

I am making an application where for it to work properly, the notifications must be set to alert.

  1. I have done my research, and I don't think this is possible, but if it is how?

  2. If it isn't possible, how do I set it so that if the user taps that it is ok if the app sends local notifications, it would set it to alert.

  3. On the xcode simulator how could I make the notification an alert.

  4. How could I Detect if notifications were on and set to alert (if thats possible)

3 Answers3

0

What notifications are you talking about, a timed notification of your own?

1. If so, all you would need to do is show a [UIAlertView][1] when your notification is supposed to appear.

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Hey"
                                                                   message:@"This is a message"
                                                                  delegate:self
                                                         cancelButtonTitle:nil
                                                         otherButtonTitles:@"Okay", nil];
[alertView show];
[alertView release];    

2. If the notification may show when the app is not launched, you can use local notifications as you mentioned with UILocalNotification . When the local notification is fired an alert will appear whether the user is in your app or not.

3. For a simulator, same as #1 if I understand what you are saying.

4. You could store the local notifications or some indicator of them in an array and refer to the array to check for pending local notifications.

ansonl
  • 786
  • 1
  • 13
  • 34
  • How would I set the UIAlertView? –  Jul 29 '13 at 12:33
  • I have updated my post with the UIAlertView code. Also, as @Herçules mentioned, if the user has set the app up for banner notifications (the default setting), all notifications will show up as banners. The alert's title and message will just be put into the banner notification. – ansonl Jul 29 '13 at 15:59
0

First register for the UILocalNotification and when the notification comes, its delegate method is called,

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification NS_AVAILABLE_IOS(4_0)

In this method you can pass the info or do whatever you want to do.

You can use UILocalNotification methods to schedule and cancel your notifications such as

- (void)presentLocalNotificationNow:(UILocalNotification *)notification NS_AVAILABLE_IOS(4_0);

- (void)scheduleLocalNotification:(UILocalNotification *)notification NS_AVAILABLE_IOS(4_0);  // copies notification
- (void)cancelLocalNotification:(UILocalNotification *)notification NS_AVAILABLE_IOS(4_0);
- (void)cancelAllLocalNotifications NS_AVAILABLE_IOS(4_0);
Sabby
  • 2,586
  • 2
  • 27
  • 41
0

look at this answer

https://stackoverflow.com/a/9137501/1305001 And https://stackoverflow.com/a/8259743/1305001

It is now user's choice to choose alert style not a programmer.

You can change your alert style from Device->Settings->Notification Center->Phone->Alert Style to :---

None
Banners
Alerts

enter image description here

Community
  • 1
  • 1
Prince Kumar Sharma
  • 12,591
  • 4
  • 59
  • 90