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 09-16-2010, 04:27 AM   #1 (permalink)
iPhone Apprentice
 
Join Date: Sep 2010
Location: Denmark
Posts: 19
yocal is on a distinguished road
Send a message via MSN to yocal Send a message via Skype™ to yocal
Question Vibrator - nothing happens

Heya all,

Still new to this, but im trying the best i can :-) Right now i've ran into a wall though...

I'm trying to make the phone vibrate by the click of a button.

- I've added the AudioToolbox-framework and imported it.
- I've connected my button to the method
- The button triggers the alert im making in the very same method
- The vibration is completely ignored
- The app doesnt crash - it just doesnt vibrate >.<

Any idea why? I've tried on several phones (All 4's with iOS 4.1):

Code:
- (IBAction)activateVibrator:(id)sender {

    AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
    
    UIAlertView *alert = [[UIAlertView alloc]
                          initWithTitle:@"It vibrated!"
                          message:nil
                          delegate:nil
                          cancelButtonTitle:nil
                          otherButtonTitles:@"OK", nil];
    [alert show];
    [alert release];
    
}
Im kinda confused

// Yoc.
yocal is offline   Reply With Quote
Old 09-16-2010, 04:49 AM   #2 (permalink)
Registered Member
 
Join Date: Jul 2010
Location: Enschede, Netherlands
Posts: 198
rickrets is on a distinguished road
Default

Did you do this:
Code:
#import <AudioToolbox/AudioToolbox.h>
??
rickrets is offline   Reply With Quote
Old 09-16-2010, 05:14 AM   #3 (permalink)
Registered Member
 
Join Date: Aug 2010
Location: Edinburgh
Posts: 209
Justinmichael is on a distinguished road
Default

Had to laugh at the thread title. lol. Immature, I know.
__________________
Justinmichael is offline   Reply With Quote
Old 09-16-2010, 05:19 AM   #4 (permalink)
iPhone Apprentice
 
Join Date: Sep 2010
Location: Denmark
Posts: 19
yocal is on a distinguished road
Send a message via MSN to yocal Send a message via Skype™ to yocal
Default

Quote:
Originally Posted by yocal View Post
- I've added the AudioToolbox-framework and imported it.
Certainly did, rickrets :-) I guess it wouldnt have compiled if i didnt :-P

It runs just fine, shows altert; but no vibration >.<

Justinmichael; heh - it wasnt even on purpose :-P

// Yoc.
yocal is offline   Reply With Quote
Old 09-16-2010, 05:22 AM   #5 (permalink)
Registered Member
 
Join Date: Jul 2010
Location: Enschede, Netherlands
Posts: 198
rickrets is on a distinguished road
Default

Yeah I noticed, after this thread I found a place to use vibration in the app I'm working on

But I can't test it at the moment, I had to download SDK 4.1 *sigh*, downloading @ work place is NOT going fast! In 60 minutes I can test it and will tell you by then if it worked at my project or not!

Cheers
rickrets is offline   Reply With Quote
Old 09-16-2010, 05:23 AM   #6 (permalink)
Registered Member
 
Join Date: Aug 2010
Location: Edinburgh
Posts: 209
Justinmichael is on a distinguished road
Default

Heh, wish I could help though bud. Not sure why it isn't working. Are you definitely trying on a phone and not an iPod? Heard that iPod doesn't vibrate.

Documentation suggests what you have wrote is correct. I'll have a dig around.
__________________
Justinmichael is offline   Reply With Quote
Old 09-16-2010, 05:28 AM   #7 (permalink)
iPhone Apprentice
 
Join Date: Sep 2010
Location: Denmark
Posts: 19
yocal is on a distinguished road
Send a message via MSN to yocal Send a message via Skype™ to yocal
Default

Quote:
Originally Posted by Justinmichael View Post
Heh, wish I could help though bud. Not sure why it isn't working. Are you definitely trying on a phone and not an iPod? Heard that iPod doesn't vibrate.

Documentation suggests what you have wrote is correct. I'll have a dig around.
Yeah, im pretty sure that my phone is an iPhone 4 It's happy to vibrate on incomming calls, so it isnt because the vibrator is broken either, hehe.
yocal is offline   Reply With Quote
Old 09-16-2010, 05:32 AM   #8 (permalink)
Registered Member
 
Join Date: Aug 2010
Location: Edinburgh
Posts: 209
Justinmichael is on a distinguished road
Default

I imported AudioToolkit and put the same code into an init method and it vibrated fine on my iPhone 4. It was very short though (and quite weak).

Try moving the vibrate call into your init method and see if it fires.
__________________
Justinmichael is offline   Reply With Quote
Old 09-16-2010, 05:34 AM   #9 (permalink)
Registered Member
 
Join Date: Aug 2010
Location: Edinburgh
Posts: 209
Justinmichael is on a distinguished road
Default

You do have to remember to add the AudioToolkit to your Target. If you do getInfo on the target and click '+' then choose 'AudioToolkit'
__________________
Justinmichael is offline   Reply With Quote
Old 09-16-2010, 05:39 AM   #10 (permalink)
iPhone Apprentice
 
Join Date: Sep 2010
Location: Denmark
Posts: 19
yocal is on a distinguished road
Send a message via MSN to yocal Send a message via Skype™ to yocal
Default

Quote:
Originally Posted by Justinmichael View Post
You do have to remember to add the AudioToolkit to your Target. If you do getInfo on the target and click '+' then choose 'AudioToolkit'
Bleh, still nothing...

I've tried to attach the code - would you give it a shot and see if it works for you?

Im using xcode 4, preview 3 - could that be why?

// Yoc.
Attached Files
File Type: zip HelloItaly.zip (46.8 KB, 6 views)
yocal is offline   Reply With Quote
Old 09-16-2010, 05:45 AM   #11 (permalink)
Registered Member
 
Join Date: Aug 2010
Location: Edinburgh
Posts: 209
Justinmichael is on a distinguished road
Default

Yeah, I've had a look. The libraries are showing up red so think something has gone wrong with the import. Delete the Red libraries and then add them again by pressing 'applekey + I Key' on Targets -> HelloItaly and then pressing + and add AudioToolbox + AVFoundation + CoreMotion + CoreLocation.
__________________
Justinmichael is offline   Reply With Quote
Old 09-16-2010, 05:56 AM   #12 (permalink)
Registered Member
 
Join Date: Aug 2010
Location: Edinburgh
Posts: 209
Justinmichael is on a distinguished road
Default

Cancel that, was nothing to do with it. For some reason it doesn't work when you put it in the IBAction but putting it in ViewDidLoad works fine.

I'm trying to figure out why.
__________________
Justinmichael is offline   Reply With Quote
Old 09-16-2010, 06:01 AM   #13 (permalink)
iPhone Apprentice
 
Join Date: Sep 2010
Location: Denmark
Posts: 19
yocal is on a distinguished road
Send a message via MSN to yocal Send a message via Skype™ to yocal
Default

Quote:
Originally Posted by Justinmichael View Post
Yeah, I've had a look. The libraries are showing up red so think something has gone wrong with the import. Delete the Red libraries and then add them again by pressing 'applekey + I Key' on Targets -> HelloItaly and then pressing + and add AudioToolbox + AVFoundation + CoreMotion + CoreLocation.
I think its because im using xcode 4, inthere they seem fine. If i open the project in xcode 3, they're red, even the UIKit, Foundation and CoreGraphics are red >.<

And i cant seem to add AVFoundation, CoreMotion or CoreLocation; they arent listed...

Anyways, wouldnt it fail to compile if it cannot find the framework?

// Yoc.
yocal is offline   Reply With Quote
Old 09-16-2010, 06:37 AM   #14 (permalink)
Registered Member
 
Join Date: Aug 2010
Location: Edinburgh
Posts: 209
Justinmichael is on a distinguished road
Default

It is fine in xCode 4 and in your code if it is in the viewDidLoad method. For some reason it doesn't like it coming off the IBAction which I can't figure out. I've tried all sorts of different perform selector methods to trick it.

Really not sure on this one. Anyone have any ideas why vibrate would work on viewDidLoad but not in an IBAction method (that is definitely being called).
__________________
Justinmichael is offline   Reply With Quote
Old 09-16-2010, 08:15 AM   #15 (permalink)
Registered Member
 
Join Date: Jul 2010
Location: Enschede, Netherlands
Posts: 198
rickrets is on a distinguished road
Default

It works perfectly fine here, in a void method...
rickrets is offline   Reply With Quote
Old 09-16-2010, 08:21 AM   #16 (permalink)
Registered Member
 
Join Date: Aug 2010
Location: Edinburgh
Posts: 209
Justinmichael is on a distinguished road
Default

Yeah, that's what I thought. Just hates IBAction for some reason.
__________________
Justinmichael is offline   Reply With Quote
Old 09-16-2010, 11:30 AM   #17 (permalink)
Pro. Game Developer
iPhone Dev SDK Supporter
 
Join Date: Feb 2009
Location: żLa Islas Hermosas?
Posts: 2,176
Kalimba is on a distinguished road
Default

Is it possible that the vibration "sound" is queued up properly, but showing the alert causes all pending sounds to be canceled? According to to docs, AudioServicesPlaySystemSound() does not allow simultaneous playback of multiple sounds, so perhaps showing the alert causes the vibration sound to get stomped by... something else. Try playing the vibration after you show the alert and see what happens.
__________________
~~ Word Flurry ~~ App Store / Website / Facebook
Kalimba is offline   Reply With Quote
Old 09-16-2010, 04:24 PM   #18 (permalink)
iPhone Apprentice
 
Join Date: Sep 2010
Location: Denmark
Posts: 19
yocal is on a distinguished road
Send a message via MSN to yocal Send a message via Skype™ to yocal
Default

Quote:
Originally Posted by Kalimba View Post
Is it possible that the vibration "sound" is queued up properly, but showing the alert causes all pending sounds to be canceled? According to to docs, AudioServicesPlaySystemSound() does not allow simultaneous playback of multiple sounds, so perhaps showing the alert causes the vibration sound to get stomped by... something else. Try playing the vibration after you show the alert and see what happens.
I've tried moving it to the viewDidLoad, and it vibrates just fine... Then i tried to put the vibration in a void method and calling that from my IBOutlet:

Code:
- (IBAction)activateVibrator:(id)sender {

    UIAlertView *alert = [[UIAlertView alloc]
                          initWithTitle:@"It vibrated!"
                          message:nil
                          delegate:nil
                          cancelButtonTitle:nil
                          otherButtonTitles:@"OK", nil];
	[alert show];
    [alert release];
    
    [self buzz];
} 

- (void)buzz {
    AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
}
But that was a nogo as well :-(

// Yoc.
yocal is offline   Reply With Quote
Old 09-16-2010, 05:13 PM   #19 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 98
rTicker is on a distinguished road
Default

Try making a NSTimer in the IBAction endpoint it to -(void)buzz?
rTicker is offline   Reply With Quote
Reply

Bookmarks

Tags
vibrator

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: 334
19 members and 315 guests
2ndSegment, bignoggins, cayladv57, cgokey, dermotos, djohnson, Domele, guusleijsten, Hamad, heshiming, linkmx, markuschow, Objective Zero, pungs, Rudy, Sloshmonster, teebee74, v1n2e7t
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,655
Threads: 94,116
Posts: 402,889
Top Poster: BrianSlick (7,990)
Welcome to our newest member, pungs
Powered by vBadvanced CMPS v3.1.0

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