App help!!!

Discussion in 'iOS Development' started by Jek570, Jun 9, 2010.

  1. Jek570

    Jek570 New Member

    Joined:
    Jun 9, 2010
    Messages:
    121
    Likes Received:
    0
    Device:
    3G iPod touch
    So I got it figured out how to get my app on my ipod, but with my app, what you do is you shake it and a message pops up. if you click dismiss, the message is supposed to go away, but it pops back up! here is the code in "shakemeviewcontroller.m" I also would like the code and where to put it.

    [OBJC]//
    // shakemeViewController.m
    // shakeme
    //
    // Created by Joren Miner on 6/4/10.
    // Copyright Rock_it Apps 2010. All rights reserved.
    //

    #import "shakemeViewController.h"

    @implementation shakemeViewController

    -(void)accelerometer

    Please Register or Log in to view images

    UIAccelerometer *)accelerometer didAccelerate

    Please Register or Log in to view images

    UIAcceleration *)acceleration {

    if (fabsf(acceleration.x) > 2.0 || fabsf(acceleration.y) > 2.0 || fabsf(acceleration.z) > 2.0) {

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle

    Please Register or Log in to view images

    "Hey!!!"
    message

    Please Register or Log in to view images

    "You shook me!!!" delegate:nil cancelButtonTitle

    Please Register or Log in to view images

    "Sorry" otherButtonTitles:nil];

    [alert show];
    [alert release];

    }
    }


    /*
    // The designated initializer. Override to perform setup that is required before the view is loaded.
    - (id)initWithNibName

    Please Register or Log in to view images

    NSString *)nibNameOrNil bundle

    Please Register or Log in to view images

    NSBundle *)nibBundleOrNil {
    if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
    // Custom initialization
    }
    return self;
    }
    */

    /*
    // Implement loadView to create a view hierarchy programmatically, without using a nib.
    - (void)loadView {
    }
    */



    // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
    - (void)viewDidLoad {

    UIAccelerometer *accelerometer = [UIAccelerometer sharedAccelerometer];
    accelerometer.delegate = self;
    accelerometer.updateInterval = 0.5f/60.0f;

    [super viewDidLoad];
    }



    /*
    // Override to allow orientations other than the default portrait orientation.
    - (BOOL)shouldAutorotateToInterfaceOrienta… {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
    }
    */

    - (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
    }

    - (void)viewDidUnload {
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
    }


    - (void)dealloc {
    [super dealloc];
    }

    @end[/OBJC]





    Please help!!!
  2. Freerunnering

    Freerunnering Member

    Joined:
    Sep 1, 2009
    Messages:
    296
    Likes Received:
    0
    Device:
    4G iPod touch
    put the code between
    [ code ]

    [ /code ]
    BBC code so the forum doesn't turn some of your stuff into different smiley faces.


    Please Register or Log in to view images

  3. Jek570

    Jek570 New Member

    Joined:
    Jun 9, 2010
    Messages:
    121
    Likes Received:
    0
    Device:
    3G iPod touch
    Ok
    [OBJC]

    //
    // shakemeViewController.m
    // shakeme
    //
    // Created by Joren Miner on 6/4/10.
    // Copyright Rock_it Apps 2010. All rights reserved.
    //

    #import "shakemeViewController.h"

    @implementation shakemeViewController

    -(void)accelerometer

    Please Register or Log in to view images

    UIAccelerometer *)accelerometer didAccelerate

    Please Register or Log in to view images

    UIAcceleration *)acceleration {

    if (fabsf(acceleration.x) > 2.0 || fabsf(acceleration.y) > 2.0 || fabsf(acceleration.z) > 2.0) {

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle

    Please Register or Log in to view images

    "Hey!!!"
    message

    Please Register or Log in to view images

    "You shook me!!!" delegate:nil cancelButtonTitle

    Please Register or Log in to view images

    "Sorry" otherButtonTitles:nil];

    [alert show];
    [alert release];

    }
    }


    /*
    // The designated initializer. Override to perform setup that is required before the view is loaded.
    - (id)initWithNibName

    Please Register or Log in to view images

    NSString *)nibNameOrNil bundle

    Please Register or Log in to view images

    NSBundle *)nibBundleOrNil {
    if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
    // Custom initialization
    }
    return self;
    }
    */

    /*
    // Implement loadView to create a view hierarchy programmatically, without using a nib.
    - (void)loadView {
    }
    */



    // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
    - (void)viewDidLoad {

    UIAccelerometer *accelerometer = [UIAccelerometer sharedAccelerometer];
    accelerometer.delegate = self;
    accelerometer.updateInterval = 0.5f/60.0f;

    [super viewDidLoad];
    }



    /*
    // Override to allow orientations other than the default portrait orientation.
    - (BOOL)shouldAutorotateToInterfaceOrienta… {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
    }
    */

    - (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
    }

    - (void)viewDidUnload {
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
    }


    - (void)dealloc {
    [super dealloc];
    }

    @end
    [/OBJC]
  4. lauNchD

    lauNchD Well-Known Member

    Joined:
    Jan 27, 2008
    Messages:
    1,844
    Likes Received:
    261
    Device:
    iPhone 5 (Black)
    Even better: use 'OBJC' instead of 'code' to get custom Objective-C syntax highlighting

    Please Register or Log in to view images



    @OP:

    I'm pretty sure the problem is that your accelerometer will sense a >2G acceleration for more than 1/120th of a second if you shake it (BTW: Why are you setting the frequency to 120 Hz? It's overkill for a simple shake detector!). Thus, every time the accelerometer checks in (120 times a second is what you told it) and the acceleration values lie above your threshold, a new alert will be created. (It seems like the same one is popping up really often, but they're all different instances).

    Here are some suggestions:
    1. If you're targeting 3.0 and higher, you can use UIKit's built-in shake detection mechanism. Then you won't even have to deal with UIAccelerometer.
    2. Once you detect a shake, tell the accelerometer to stop updating, then show the alert. This will save your battery until the accelerometer needs to be used again. Implement a delegate method for the alert to call in which you start accelerometer updates again.

    ^ This is fairly simple; all of these methods (unintentional pun fail) are well-documented. Try to do it on your own. If you can't do this, we may be able to help you further.
  5. Jek570

    Jek570 New Member

    Joined:
    Jun 9, 2010
    Messages:
    121
    Likes Received:
    0
    Device:
    3G iPod touch
    I'm new to this. Can u give me the code so I can learn and where to put it?
  6. lauNchD

    lauNchD Well-Known Member

    Joined:
    Jan 27, 2008
    Messages:
    1,844
    Likes Received:
    261
    Device:
    iPhone 5 (Black)
    At least elaborate with method you'd rather use. Do your apps have to be 2.x compatible?
    Look at Xcode's documentation on UIAccelerometer; copy-pasting stuff from tutorials doesn't really help you grasp basic concepts.
  7. Jek570

    Jek570 New Member

    Joined:
    Jun 9, 2010
    Messages:
    121
    Likes Received:
    0
    Device:
    3G iPod touch
    I need code!!! I learn by exploring what others have done.
  8. Pelaez-1

    Pelaez-1 New Member

    Joined:
    May 5, 2008
    Messages:
    822
    Likes Received:
    0
    Device:
    iPhone
    No you don't. You think you do, but you are limited to what do whatever the code you found does.
  9. Jek570

    Jek570 New Member

    Joined:
    Jun 9, 2010
    Messages:
    121
    Likes Received:
    0
    Device:
    3G iPod touch
    Yes I do! You don't know crap about me. I am extreamly gifted, and I look at things that others have done and piece togeter different parts of code to see how it works. If you don't even give me code, that shows that u can't figure it out.
  10. Axis

    Axis Super Moderator Staff Member

    Joined:
    Dec 2, 2007
    Messages:
    6,288
    Likes Received:
    133
    Device:
    iPhone 4S (White)
    You don't know what you are missing then. For example, why don't you explain your code line by line?
    Impenetrable logic!

Share This Page