Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 07-06-2010, 05:57 PM   #1 (permalink)
Banned
 
Join Date: Jun 2010
Posts: 91
maxk77 is on a distinguished road
Default IBACTION repeat

hi, i have this ibaction:
Code:
-(IBAction)vibrate {
	AudioServicesPlayAlertSound(kSystemSoundID_Vibrate);
}
However i would like the iphone to vibrate until the user presses another button to stop the iphone vibrating. I know how to stop it vibrating i just need to know how to continue the vibrations.
thanks
maxk77 is offline   Reply With Quote
Old 07-06-2010, 06:48 PM   #2 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 577
Speed is on a distinguished road
Default

Quote:
Originally Posted by maxk77 View Post
hi, i have this ibaction:
Code:
-(IBAction)vibrate {
	AudioServicesPlayAlertSound(kSystemSoundID_Vibrate);
}
However i would like the iphone to vibrate until the user presses another button to stop the iphone vibrating. I know how to stop it vibrating i just need to know how to continue the vibrations.
thanks
Have an NSTimer call the vibrate over and over (lasting as long as the vibrate does), for example, 2 second intervals. Then call [timer invalidate]; on your other IBAction to stop the timer.
Speed is offline   Reply With Quote
Old 07-06-2010, 06:56 PM   #3 (permalink)
Banned
 
Join Date: Jun 2010
Posts: 91
maxk77 is on a distinguished road
Default

i dont really understand would you mind implementing it into my code? thanks a lot max.
maxk77 is offline   Reply With Quote
Old 07-06-2010, 07:13 PM   #4 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 577
Speed is on a distinguished road
Default

Code:
-(IBAction)vibrate {
	
	AudioServicesPlayAlertSound(kSystemSoundID_Vibrate);
	
	timer = [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(vibrateTimer) userInfo:nil repeats:YES];	
}

-(void)vibrateTimer {
	AudioServicesPlayAlertSound(kSystemSoundID_Vibrate);
}

-(IBAction)stopVibration {
	[timer invalidate], timer = nil;
	//stopVibrationHere
}
Try this, I think it should work.
Speed is offline   Reply With Quote
Old 07-06-2010, 07:31 PM   #5 (permalink)
Banned
 
Join Date: Jun 2010
Posts: 91
maxk77 is on a distinguished road
Default

it now looks like this,
Code:
#import <AudioToolbox/AudioToolbox.h>
@implementation Vibration_ButtonViewController

-(IBAction)vibrate {
	
	AudioServicesPlayAlertSound(kSystemSoundID_Vibrate);
	
	timer = [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(vibrateTimer) userInfo:nil repeats:YES];	
}

-(void)vibrateTimer {
	AudioServicesPlayAlertSound(kSystemSoundID_Vibrate);
}

-(IBAction)stopVibration {
	[timer invalidate], timer = nil;
	//stopVibrationHere
}
and i am getting an error saying timer undeclared. What is wrong with it?
maxk77 is offline   Reply With Quote
Old 07-06-2010, 09:07 PM   #6 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 577
Speed is on a distinguished road
Default

You have to declare timer as an NSTimer in your .h file
Speed is offline   Reply With Quote
Old 07-07-2010, 10:54 AM   #7 (permalink)
Banned
 
Join Date: Jun 2010
Posts: 91
maxk77 is on a distinguished road
Default

how do i do that?
maxk77 is offline   Reply With Quote
Old 07-07-2010, 11:02 AM   #8 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 577
Speed is on a distinguished road
Default

@interface ExampleViewController : UIViewController {

NSTimer *timer;
}

@end
Speed is offline   Reply With Quote
Old 07-07-2010, 11:07 AM   #9 (permalink)
Banned
 
Join Date: Jun 2010
Posts: 91
maxk77 is on a distinguished road
Default

yeh yeh i remembed thanks so much for you help its working perfectly.
maxk77 is offline   Reply With Quote
Old 07-07-2010, 11:10 AM   #10 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 577
Speed is on a distinguished road
Default

Quote:
Originally Posted by maxk77 View Post
yeh yeh i remembed thanks so much for you help its working perfectly.
No problem
Speed is offline   Reply With Quote
Reply

Bookmarks

Tags
aaa

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 331
9 members and 322 guests
anothermine, Chickenrig, firecall, givensur, iNet, michaelhansen, Objective Zero, PixelInteractive, stanny
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,118
Posts: 402,892
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 12:29 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0