Когда я отправляю пакет с устройства Bluetooth на iPhone, iPhone вибрирует.
Пакет обычно принимается, но вибрации не происходит.
В чем проблема?
Ниже фактический источник.
- (void)runVibration:(NSMutableArray <__kindof NSNumber *> *)params {
NSLog(@"******params %@", params);
int param = [[params objectAtIndex:0] intValue];
NSLog(@"****** Vibrate params :%d", param);
[[Common getInstance] dovibrate:(param/100)];
performSelectorOnMainThread:@selector(dovibrate2:) withObject:params waitUntilDone:YES];
}
-(void) dovibrate:(NSTimeInterval) sec
{
if(self.vibratortimer && [self.vibratortimer isValid])
{
[self.vibratortimer invalidate];
self.vibratortimer = nil;
}
self.g_time = [NSDate dateWithTimeIntervalSinceNow:sec];
self.vibratortimer =
[NSTimer scheduledTimerWithTimeInterval:0.1f target:self selector:@selector(stopVibration) userInfo:nil repeats:YES];
}
- (void) stopVibration {
NSDate *now = [NSDate date];
NSTimeInterval diff = [now timeIntervalSinceDate:self.g_time];
if (diff >= 0)
{
[self.vibratortimer invalidate];
self.vibratortimer = nil;
AudioServicesDisposeSystemSoundID (kSystemSoundID_Vibrate);
}
else
{
AudioServicesDisposeSystemSoundID (kSystemSoundID_Vibrate);
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
}
}
Метод вызова: runVibration -> dovibrate -> stopVibration
Это также не происходит, когда применяется.
A
dispatch_async(dispatch_get_main_queue(), ^{
AudioServicesDisposeSystemSoundID (kSystemSoundID_Vibrate);
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
});