I have implemented application in which there is one speedo meter and three buttons.
1)Start 2)stop 3)review
When i press the start button than UIAccelerometer is start
when i press stop button than UIAccelerometer is stop.
when i press review button than in next view it will show hisry of time.
My problem is that:
When i press the start button than apliuction is terminated.
how to start and stop UIAccelerometer ??
Use this to start the accelerometer measurement via delegate method accelerometer:didAccelerate:
[UIAccelerometer sharedAccelerometer].delegate = self;
And this to stop it
[UIAccelerometer sharedAccelerometer].delegate = nil;
To "start" and "stop" accelerometer (i.e. to register and ignore the accelerometer inputs), set the UIAccelerometer delegate to the class which will use the data (on start) or set the delegate to nil (to stop). If you set the delegate to nil, the accelerometer data will not be used by your app.
In case the issue is something else (an error in your code etc), please post what you have tried till now and you'll get more helpful answers.
Comment out the UIAccelerometer code and then try start, stop, review, and start to see if it still crashes.
Related
I'm working on compas-AR app. I have UIImagePickerViewController so I can have background from device camera. Inside UIView overlay I put all UI buttons/subviews. Every method has a NSLog() at the very beginning, so I can track in logs where app is going. Unfortunatelly I'm stuck. After downloading no data I use this UIView nothingView - which I declared and added with all subviews within viewDidAppear:(BOOL)animated. Here comes the problem: nothingView is shown, but any interaction (rotating device, pressing my action UIButtons etc) is suspending app and all I got in logs is this:
2013-05-29 15:49:53.657 CloudReco copy[6246:707] GeoVC: targetsRequestDidFinishForContent
2013-05-29 15:49:53.659 CloudReco copy[6246:707] GeoVC: there is no data from targets dictionary
2013-05-29 15:49:53.662 CloudReco copy[6246:707] GeoVC: showNothing
2013-05-29 15:49:53.664 CloudReco copy[6246:707] GeoVC: showNothing 2
(gdb)
I did use anylizer, but it didn't point in any direction here. If I did only receive any method's NSLog I could try to follow, but with any trace I'm helpless.
Here is code snippet called when I send notification that nothing was found:
-(void)showNothing:(NSNotification *)notification{
NSLog(#"GeoVC: showNothing");
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(#"GeoVC: showNothing 2");
loadingView.hidden = YES;
closeButton.hidden = NO;
startView.hidden = YES;
gestrec.enabled = NO;
nothingView.hidden = NO;
[locationManager stopUpdatingLocation];
});
}
After that is ok, unless I rotate device or push any action button...
any help appreciated
note: I'm using iOS 5.1 and Xcode 4.2
update: that's all I got. Somehow dealloc is being called after all operations, despite I don't hide/exit/release any view - at least not "me"
(gdb) bt
#0 0x37de2f78 in CoreLocationVersionNumber ()
#1 0x334b42bc in ?? ()
Insure that you have an ivar or property keeping a strong reference to location objects, and never release them (ie nil them) in a delegate callback, rather dispatch a block to the main queue to release it. Ask me how I know this :-)
I have a toggle menu which toggle between the words "Pause" and "Resume" when it is pressed, which also pause and resume the whole game. This means when playing, the menu will be shown as "Pause" (tap here to pause), when pausing the menu will be shown as "Resume" (tap here to resume).
Here is the problem, if I tap the home button after I pause the game, then go back into it, it resumes itself and the pause menu is shown as "Resume". And this doesn't make sense to me. The best way I want is to pause the game whenever go into the background and resume from background. I look at the following methods, but they don't really work:
-(void)applicationWillResignActive:(UIApplication *)application{
}
- (void)applicationDidBecomeActive:(UIApplication *)application{
}
-(void)applicationWillEnterBackground:(UIApplication*)application{
}
-(void)applicationDidEnterBackground:(UIApplication *)application {
}
I even just put CCLOG in all of those methods, but nothing has been called. Is there something I am need to put/declare before I use those methods?
Sorry, it is a bit too long to read. Hope you can help me. Thank you.
I'm not sure why, but for my experience (not cocos2d), there's no additional implementation if want apply those methods.
perhaps, you should try look at this.
link 1 & link 2
-(void)applicationWillResignActive:(UIApplication *)application{
}
- (void)applicationDidBecomeActive:(UIApplication *)application{
}
you need custom your cocos2d CCDIRECTOR class. And get now display layer. then active it pause or resume function. All this must need some protocol.
These methods are invoked when the iOS forces your application in the background, or resumes execution of your application, ie they are signals you receive when an external event causes your application to go to background, or come back from it. You should not try to invoke them directly. There is no real relationship with a 'user created' menu like yours (like your Resume/Pause menu), unless you make the relationship explicit.
So , in the following method:
- (void)applicationWillResignActive:(UIApplication *)application {
NSLog(#"<%#>:applicationWillResignActive - received signal, pausing sharedDirector.",[self class]);
// here : place your code for forcing your menu in the 'Resume' state
// i am assuming some kind of change in a button, and
// a state variable of your own that define and control
// what it means to be 'paused' from your applications point of
// view
// then force the director to pause (animations, scheduling, touch, etc ...)
[[CCDirector sharedDirector] pause];
}
after, when the iOS hands you back control by placing your application in the forground as the running application:
- (void)applicationDidBecomeActive:(UIApplication *)application {
NSLog(#"<%#>:applicationDidBecomeActive - received signal, resuming sharedDirector.",[self class]);
[[CCDirector sharedDirector] resume];
}
You dont really need to do anything fancy here other than restart the CCDirector, since your menu is in the 'Resume' state, garanteed. When user presses Resume, you will start your game again and put the menu in the 'Pause' state.
I'm trying to force an action to complete before another action can be called. I've looked all over for different examples of timing delays and CCSequencing and this is what i have so far, but it still isn't working. I need the full .5 to come out before another action (whether it be left, right or down) can be called. Everything is working as long as you don't hit the buttons before an action finishes, thats when the previous action is cut short.
-(void) moveup{
CCNode *mySprite = [self getChildByTag:kTagSprite];
//moves sprite up 30 pixels in 1/2 second
[mySprite runAction: [CCMoveTo actionWithDuration:.5 position:ccp(mySprite.position.x, mySprite.position.y+30)]];
}
//this is inside CCtouchesbegan. upsprite is a box that gets clicked to move the object up
if(CGRectContainsPoint([upsprite boundingBox], point)){
//should call CCSequence of events, method moveup, and then CCDelayTime, forcing a pause
[self runAction:[CCSequence actions:[CCCallFuncND actionWithTarget:self selector:#selector(moveup) data:nil], [CCDelayTime actionWithDuration:.5], nil]];
}
I've tried pausing using [[CCDirector sharedDirector] pause] but this freezes everything, including the sprite I'm moving. The CCDelayTime doesn't seem to be working in my current example.
I know this question is kind of a duplicate of a couple others about ccsequencing, so if it needs to be marked as a dupe, that's fine, but I'd really like some help as it's really holding me back.
You could make a BOOL "lock" variable, and only run the action on "mySprite" :
if(lock) {[mySprite runAction:...];}
set the BOOL lock to NO in the beginning and everytime you begin the action set it to "YES"...then add a CCCallFunc to the CCSequence to set the lock back to "NO"
I have an application that requires the iPhone screen to remain active (or not, depending on user choice). I've done this by disabling the application idle timer, which works fine and dandy until I start playing media via the MPMusicPlayerController. Due to a bug in the SDK, this then reenables the idle timer with no apparent way to disable it again.
My app flow is:
App starts
Screen stays on
<...time passes...>
Play audio file
Idle timer kicks in
Screen turns off
I have an empty audio file playing in the background to stop the phone going into deep sleep, but I'd really like to keep the screen unlocked too.
Has anyone managed to figure out a workaround for this?
I had a similiar problem, and found a fix for it. The fix might work for you too:
I call a method periodically (every 10 seconds), which sets idleTimerDisabled first to NO, then to YES.
- (void)calledEveryTenSeconds
{
[UIApplication sharedApplication].idleTimerDisabled = NO;
[UIApplication sharedApplication].idleTimerDisabled = YES;
}
Only setting to YES alone does not fix the problem. It seems the property has to change first to be recognized by UIApplication.
My problem was, that the screen kept turning dark as soon as I switched music tracks on the iPod player via the headphone remote. My guess is, that this is the same issue as you are experiencing.
You should simply turn off the idle timer. What I usually do in a viewcontroller that needs to stay 'awake' is this:
- (void) viewWillAppear:(BOOL)animated
{
[[UIApplication sharedApplication] setIdleTimerDisabled: YES];
}
- (void) viewWillDisappear: (BOOL) animated
{
[[UIApplication sharedApplication] setIdleTimerDisabled: NO];
}
This will make sure the screen will not get locked due to user inactivity.
I found a solution to this problem. Invoke a method that disables the idleTimer in about 5 seconds after you start playing the music. It's a bit of a hack, but it is a workaround.
[[SoundEngine mainEngine] playMusic];
[self performSelector:#selector(setIdleTimeDisabled) withObject:nil afterDelay:5.0];
- (void) setIdleTimeDisabled {
[UIApplication sharedApplication].idleTimerDisabled = YES;
NSLog(#"Setting idleTimer to TRUE");}
let player = MPMusicPlayerController.applicationMusicPlayer()
player.setQueueWithStoreIDs(["some id"])
player.play()
player.pause()
I'm trying to use the UIImagePickerController interface from OS 3.1, with the cameraOverlayView and takePicture, but I've clearly failed to understand how this works, and so I'm not getting the behaviour I want.
What I want to do is open the camera and take a picture automatically without having to having the user interact with the picker or edit the image. So I subclass UIImagePickerController (similar to the example in http://github.com/pmark/Helpful-iPhone-Utilities/tree/master/BTL%20Utilities/) and turn off all of the controls:
- (void)displayModalWithController:(UIViewController*)controller animated:(BOOL)animated {
self.sourceType = UIImagePickerControllerSourceTypeCamera;
self.showsCameraControls = NO;
self.navigationBarHidden = YES;
self.toolbarHidden = YES;
// Setting the overlay view up programmatically.
ipView = [[ImagePickerView alloc] init];
self.cameraOverlayView = ipView;
[controller presentModalViewController:self animated:NO];
}
In the overlayView, I've managed to force the takePicture method of UIImagePickerController to fire (I know this, because I can NSLog it, and I hear the sound of the camera taking a picture). The overlayView shows up just fine. However, the delegate method didFinishPickingMediaWithInfo: never gets called, and imagePickerControllerDidCancel doesn't get called either.
So, how do I either get the delegate methods to get called, or save the picture by overriding the takePicture method? (I have no idea how to capture the picture data here, and Google seems to have failed me). I can't help feeling that I've failed to understand how the guts of UIImagePickerController works, but the docs aren't overly helpful:
e.g.:
"You can provide a custom overlay view to display a custom picture-taking interface and you can initiate the taking of pictures from your code. Your custom overlay view can be displayed in addition to, or instead of, the default controls provided by the image picker interface."
or from showCameraControls:
"If you set this property to NO and provide your own custom controls, you can take multiple pictures before dismissing the image picker interface." - How do I dismiss the picker interface?
Note: the delegate is set properly in IB, so that's not the problem.
Thanks for any help you can provide!
I've found that you just have to wait "long enough" before calling takePicture, or it just silently fails. I don't have a good answer for how to determine the minimum value of "long enough" that will always work, but if you set a timer and wait five or ten seconds you should be okay. It would be nice if it returned some kind of an "I'm not ready to take a picture yet, sorry" error either directly from takePicture or through the delegate, but as far as I know it doesn't.
As an update to my own question: It turns out that I was trying to use takePicture too early. When I moved the action to a button on the overlay and sent takePicture from that button (once the picker was presented modally), the delegate methods fired as they should. I don't know if what I wanted is achievable - taking the image without having to press that button, automatically - but if it is, it will probably have to be done by sending takePicture sometime after I was trying to use it.
-(void)imageMethod:(id)sender{
imagePickerController = [[UIImagePickerController alloc]init];
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePopover=[[UIPopoverController alloc]initWithContentViewController:imagePickerController];
[imagePopover presentPopoverFromRect:importButton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];
}