我的应用程序中的iOS闹钟功能

时间:2013-07-26 07:41:01

标签: iphone ios uilocalnotification alarm

我正在开发iOS应用程序,我需要开发以下警报标准功能。

  1. 设置自定义音(或静音)
  2. 设置振动(是/否)
  3. 设置暂停(是/否和暂停持续时间)
  4. 我做过研究,没有发现任何帮助,首先我想知道它真的有可能吗? iOS上的这些功能有任何限制吗?如果有可能请引导我,以便我可以探索。

    提前完成。

2 个答案:

答案 0 :(得分:0)

有可能做到。您必须为其发布LocalNotification。看看这个post

要创建振动,您可以使用AudioToolBox.framework。

AudioServicesPlayAlertSound(kSystemSoundID_Vibrate); AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);

答案 1 :(得分:0)

 //   Yes it is possible ,for alarm you have to use UILocalNotification class 
     For example :

    UILocalNotification *localNotification = [[UILocalNotification alloc] init];
    //---set the notification to go off in 10 seconds time---
    localNotification.fireDate =[[NSDate alloc] initWithTimeIntervalSinceNow:10];
    //---the message to display for the alert---
    localNotification.alertBody = message.text; localNotification.applicationIconBadgeNumber = 1;
    //---uses the default sound---
    localNotification.soundName = UILocalNotificationDefaultSoundName; //---title for the button to display---
    localNotification.alertAction = @”View Details”;

    //---schedule the notification---
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];

    //---display the notification now---
    [[UIApplication sharedApplication] presentLocalNotificationNow:localNotification];

    - (void) application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@”Inside
    application:didReceiveLocalNotification:”
    message:notification.alertBody

    delegate:self cancelButtonTitle:@”OK” otherButtonTitles:nil];

    [alert show];
    [alert release]; }

//application:didReceiveLocalNotification: method is also called when the
application is running and the local notification is fired.