Question regarding vibration for phone

Joined
Aug 23, 2012
Messages
2
Reaction score
0
Points
1
Ok im a little stuck regarding this. My question is I have the application with two buttons that does add and subtract with the numbers displayed on a label. The question I'm having is when a certain number is displayed on the label, lets say 22, the phone vibrates only on 22.

Here is my code so far, thank you for the help!

StartCountViewController.M

Code:
#import "StartCountViewController.h"

@implementation StartCountViewController


int Count=0;

-(void)awakeFromNib {
	
	startCount.text = @"0";
}


- (IBAction)addNumber {
	
	if(Count >= 999) return;
	NSString *numValue = [[NSString alloc] initWithFormat:@"%d", Count++];
	startCount.text = numValue;
	[numValue release];
}

- (IBAction)subtractNumber {
	
	if(Count <= 0) return;
	NSString *numValue = [[NSString alloc] initWithFormat:@"%d", Count--];
	startCount.text = numValue;
	[numValue release];
        
}


- (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


StartCountViewController.M

Code:
#import <UIKit/UIKit.h>

@interface StartCountViewController : UIViewController {

	IBOutlet UILabel *startCount;
}

//@property(nonatomic, retain) UILabel *startCount;

- (IBAction)addNumber;
- (IBAction)subtractNumber;

@end
 

Raz0rEdge

Well-known member
Staff member
Moderator
Joined
Jul 17, 2009
Messages
15,770
Reaction score
2,110
Points
113
Location
MA
Your Mac's Specs
2022 Mac Studio M1 Max, 2023 M2 MBA
For starters do the following in your header file:
Code:
#import <AudioToolbox/AudioServices.h>
Then in your addNumber and subtractNumber functions, you can do the following
Code:
if (Count == 22) {
       AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
}
This is vibrate the phone when Count is 22 or however you decide what the actual number to vibrate on is..
 
OP
L
Joined
Aug 23, 2012
Messages
2
Reaction score
0
Points
1
Well thank you so much, forgot the **** bracket.. One more question this is probably a easy one also, when im adding up and down, the addition button will subtract for one number then start adding again.. Same goes for the subtraction button, it will add one then subtract.. any reason why this is occurring?
 

Raz0rEdge

Well-known member
Staff member
Moderator
Joined
Jul 17, 2009
Messages
15,770
Reaction score
2,110
Points
113
Location
MA
Your Mac's Specs
2022 Mac Studio M1 Max, 2023 M2 MBA
Within IB did you make the connection between the add and subtract buttons to the right action? So check on that..
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top