Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8936111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:08:40+00:00 2026-06-15T10:08:40+00:00

I am working on an app that would play a beep for each position

  • 0

I am working on an app that would play a beep for each position the user holds their iOS device (standing, lying on its front/back, or on its side). At the moment, I am able to play a sound when the user has the device on its side, however, the problem is that because I have the accelerometer values linked with the slider, the beeping sound is continuous (i.e. it plays the sound as long as the user is holding the device on its side), rather than just once.

I would like the user to simply hold the device steady on its side, and then a single beep sound is made, allowing the user to then hold the device in the other positions in turn, and wait for another beep sound. I want the user to go step by step by step and hold the device in each position one at a time, moving on to the next position only after hearing a beep.

Here is the code that I am working with:

- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration
{

    NSLog(@"(%.02f, %.02f, %.02f)", acceleration.x, acceleration.y, acceleration.z);
    slider.value = acceleration.x;

    if (slider.value == -1)
        [self pushBeep];

    else if (slider.value == 0.00)
        [self pushBap];

    else if (slider.value == 1)
        [self pushBop];

...

and here is the code for my pushBeep() method (FYI, the methods pushBeep/pushBap/pushBop are all identical):

-(void) pushBeep {

    NSString *soundPath =[[NSBundle mainBundle] pathForResource:@"beep-7" ofType:@"wav"];
    NSURL *soundURL = [NSURL fileURLWithPath:soundPath];

    NSError *ierror = nil;
    iPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:soundURL error:&ierror];

    [iPlayer play];
}

Can anyone figure out what is the problem here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T10:08:41+00:00Added an answer on June 15, 2026 at 10:08 am

    I think instead of manually polling the accelerometer you should use the built in Orientation Notifications. You could use something like the below if you needed FaceUp and FaceDown orientations. Or you can use the second method for simply landscape, portrait.

    First Method that relies on the device orientation. Important if you need FaceUp or FaceDown orientations or if you don’t have a UIViewController.

    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    [[NSNotificationCenter defaultCenter]
       addObserver:self selector:@selector(orientationChanged:)
       name:UIDeviceOrientationDidChangeNotification
       object:[UIDevice currentDevice]];
    

    And here is the method to build.

    - (void) orientationChanged:(NSNotification *)note
    {
       UIDevice * device = note.object;
       switch(device.orientation)
       {
           case UIDeviceOrientationPortrait:
           /* Play a sound */
           break;
    
           case UIDeviceOrientationPortraitUpsideDown:
           /* Play a sound */
           break;
    
           // ....
    
           default:
           break;
       };
    }
    

    Second Method that relies on interfaceOrientations of a UIViewController.

    - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
    {
        switch (toInterfaceOrientation) {
            case UIInterfaceOrientationLandscapeLeft:
                /* Play a Sound */
                break;
    
            case UIInterfaceOrientationPortrait:
                /* Play a Sound */
                break;
    
                // .... More Orientations
    
            default:
                break;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on an iOS and Android app that allows the user to stream/play
I'm working on a Silverlight app that would allow a user to upload a
I'm currently working on an app that allows the user to play (automatically scroll)
I'm working on an app that creates an user profile. I need to be
I'm working on an App that runs a webservice hosted an Android device. I'm
I'm working on an app that would display a remote html and use local
I'm working on a Grails web app that would be similar in access patterns
I'm working on an app that would allow people to enter arbitrary URL's that
I have a web app that I'm working on that I would like the
I am working on an app that has a TabView controller, and in each

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.