ios開発連続携帯振動(kSystemSoundID_Vibrate連続振動)
最近機能して、メッセージを受け取る時連続的に振動します.以前はAudioServicesPlaySystemSound(kSystemSoundID_Vibrate)が呼び出されていました.一度だけ震える.次のコードは連続振動ですが、設定の遅延時間と関係がありますよ.私は1秒設置しましたが、約2回しか振動しませんでした.技術的に注意すべきは,単一例を用いてc++の関数コールバックを実現したことである.
#import AVFoundation/AVFoundationを加える.h @implementation Manager + (Manager *)shared { static Manager *sharedInstance = nil ; static dispatch_once_t onceToken; dispatch_once (& onceToken, ^ { sharedInstance = [[self alloc] init]; }); return sharedInstance; } - (id)init { if (self = [super init]) {
} (void)addVibrate { AudioServicesAddSystemSoundCompletion(kSystemSoundID_Vibrate, NULL, NULL, vibrateCallback, NULL); AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
}(void)removeVibrate{[self performSelector:@selector(stopVibrate)withObject:nil afterDelay:1];//1秒遅延を設定} void vibrateCallback(SystemSoundID sound,void*clientData){AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);//振動
} -(void)stopVibrate { [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(stopVibrateSound) object:nil]; AudioServicesRemoveSystemSoundCompletion(kSystemSoundID_Vibrate); } @end
#import AVFoundation/AVFoundationを加える.h @implementation Manager + (Manager *)shared { static Manager *sharedInstance = nil ; static dispatch_once_t onceToken; dispatch_once (& onceToken, ^ { sharedInstance = [[self alloc] init]; }); return sharedInstance; } - (id)init { if (self = [super init]) {
}
return self;
}
}
[[SettingManager shared] removeSoundID_Vibrate];
} -(void)stopVibrate { [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(stopVibrateSound) object:nil]; AudioServicesRemoveSystemSoundCompletion(kSystemSoundID_Vibrate); } @end