Change the numberWithInt
call into numberWithFloat
, and change the intensity so it's between 0 and 1. I thought it was weird when they used an int
rather than a float
.
Edit: Here's a copy/paste that should work for your code to invoke custom vibration:
#pragma mark - Custom vibration methods
-(void)invokeCustomVibrationWithStartStopTimes:(NSArray*)startStopTimes andIntensity:(float)intensity {
BOOL startOrStop = YES;
NSMutableArray* arr = [@[] mutableCopy];
double time = 0;
for (NSNumber *x in stopStartTimes) {
[arr addObject:x]
startOrStop = !startOrStop;
[arr addObject:@(startOrStop)];
time = [x doubleValue] / 1000.0;
}
AudioServicesPlaySystemSoundWithVibration(4095,nil,{@"VibePattern":arr,@"Intensity":@(intensity)})
[self performSelector:@selector(stop) withObject:nil afterDelay:time];
}
-(void)stop {
AudioServicesStopSystemSound(4095); // stop buzzing the phone
}
For startStopTimes
, it should alternate between times started and times stopped. Passing in this array:
@[@(2000), @(1000), @(1000), @(500)]
Will do what the example code did. In this case, it will start for 2000 ms, stop for 1000 ms, start for 1000 ms, and stop for 500 ms.
stop
is called to stop the sound. The way I have it set up, it stops sounds after the total amount of time sent in.
You may have noticed I've been using array/number literals rather than using [NSArray arrayWithObjects: ... , nil];
or [NSNumber numberWith...];
. This makes your code a lot shorter. Also, I marked the beginning with a #pragma mark
. Use that to organize it better. Hope it helps!