How to create a custom alarm which can be set for random days in a week without using local notifications?

StackOverflow https://stackoverflow.com/questions/12073035

سؤال

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.

هل كانت مفيدة؟

المحلول

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 :-)

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top