Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How I can open native alarm clock in iphone by using code?

Tags:

iphone

alarm

I have to crate a sample app in which when I clicked a button that should open the native alarm clock so that user can use it for setting alarm?

like image 358
Sanoj Kashyap Avatar asked Jan 04 '12 06:01

Sanoj Kashyap


3 Answers

If the Clock app supported a URL scheme, like the Phone app’s tel:// or the Mail app’s mail://, you could open it with the standard [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"..."]] approach. Unfortunately, to my knowledge, it doesn’t, so all you can really do is prompt the user to open that app themselves to set up the alarm.

Alternatively, you can have your app set up a local notification to act as an alarm using UILocalNotification, which you can find plenty of information about by searching this site.

like image 83
Noah Witherspoon Avatar answered Sep 28 '22 05:09

Noah Witherspoon


For default app MobileClock.app exists several url scheme. If u have a look in system files and open content for MobileClock.app u will find in info.plist private url scheme:

  • clock-worldclock,
  • clock-alarm,
  • clock-stopwatch,
  • clock-timer,
  • clock-timer-running .

Which using them should be possible to run app externally but only from Today widgets. Also the same for the mobile notes app.

like image 35
Evgeny Zrorin Avatar answered Sep 28 '22 05:09

Evgeny Zrorin


Two steps required.

Add the URL to info.plist CFBundleURLSchemes

<array>
        <dict>
            <key>CFBundleTypeRole</key>
            <string>Editor</string>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>clock-alarm</string>
                <string>clock-stopwatch</string>
            </array>
        </dict>
</array>

Call sharedApplication's openURL

[[UIApplication sharedApplication] 
  openURL:[NSURL URLWithString:@"clock-alarm:"]];
];
like image 40
Evan Michael Kyle Avatar answered Sep 28 '22 05:09

Evan Michael Kyle