2

I have studied some of the following questions, that are::

1.) How to set alarm for selected days in iphone?

2.) iPhone alarm using repeated local notifications

3.) How to set the alarm in iPhone and save in local notification?

but they all are using local notifications. I am facing problem with local notification as I have to use three buttons on an Alarm View which are: Snooze, Ignore and Okay. I have to perform custom actions on each button click.

Please help me with this stuff.

Suggestions accepted.

Thanks in advance.

Kuldeep.

Community
  • 1
  • 1
Kuldeep Singh
  • 336
  • 3
  • 12
  • That's simply not possible, sorry. – Fabian Kreiser Aug 22 '12 at 12:24
  • If you want to notify the user about anything that happens while your app isn't running, you'll have to use local/push notifications. You can still present a custom view when your app is opened in response to the notification. – Fabian Kreiser Aug 22 '12 at 12:35
  • 1
    @FabianKreiser: Sir, can we put three buttons in local notification pop up and define the custom action on their clicks?? – Kuldeep Singh Aug 22 '12 at 12:41
  • 1
    No, that's not possible. – Fabian Kreiser Aug 22 '12 at 12:41
  • if its possible, just have a 2 step solution, when the user presses "OK" in the notification a second window appears (ie the app opens) to ask the other question. It sounds worse than it turns out to be - I used this approach and the users are happy with it - don't nkow if this is a goable solution for you though... what you are asking is a no-issue on Android widgets though :-) – user387184 Aug 22 '12 at 13:21
  • @user387184:Sir, Could u please tell me that How to show only one button in local notification in iphone and add target action for that.. – Kuldeep Singh Aug 22 '12 at 13:30
  • You cannot infuence the way notifications pop up - except of in the settings in iPhone. So what I mean is to create one screen that appears when pressing the "OK" on the confirmation to bring the user to the options screen directly. I add some code in my answer... – user387184 Aug 22 '12 at 14:01
  • we can not access that alarms in our app so we have to create new alarms reminder for reminding particular action like i wan tot remind the user on custom days of week.. – Kuldeep Singh Aug 23 '12 at 07:08

1 Answers1

0

In you app delegate...

- (void) presentWidget: (NSString*)theDisplayedText {
    BOOL widgetIspresent = [WidgetVC widgetIsCurrentlyPresented];

    if (!widgetIspresent) {
        WidgetVC *widgetVC = [[WidgetVC alloc] initWithNibName:@"WidgetVC" userInfoString:theDisplayedText bundle:nil];

        widgetVC.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
        widgetVC.userInfoStr = theDisplayedText;
        [mainScreenManager presentViewController:widgetVC animated:YES completion:nil];
    }
}

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        UILocalNotification *localNotif = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
        if (localNotif) {
            NSLog(@"Recieved Notification  didFinishLaunchingWithOptions %@",localNotif);
            NSString *theDisplaytext = [localNotif.userInfo valueForKey:@"someKey"];
            //here we have to handle whatever notification was pressed - that might also be an old aready passed one
            //this all is checked when the widget opens - it will show if the notification is OK or too old
            [self presentWidget: theDisplaytext ];
        } else {
            //so we started the app normally, not via local notification
            [self presentWidget];

        }

        return YES;
    }


// Handle the notificaton when the app is running
- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)localNotif {
    // Handle the notificaton when the app is running
    NSLog(@"Recieved Notification didReceiveLocalNotification %@",localNotif);
    NSString *theDisplaytext = [localNotif.userInfo valueForKey:@"someKey"];
    [self presentWidget: theDisplaytext];
}

You need a way to start the UIViewController for the widget, I just created a mainScreenManager helper.

So on the widgetVC you have your "Snooze" and "OK" while the "Ignore" is just the ignoring of the notification itself.

Hope this gets you on an usable track...

ps I ported my app from Android to iPhone, that's why I used the name "widgetVC" for this screen. On Android it is implemented as a widget. Hope no iPhone lover feels offended :-)

user387184
  • 10,953
  • 12
  • 77
  • 147