iOS에 맞춤형 진동을위한 API가 있습니까?
iOS 5부터 사용자는 경고 및 벨소리에 대한 사용자 지정 진동 패턴을 만들 수 있습니다. 다음 스크린 샷은 하나를 만들기위한 UI를 보여줍니다 (iOS 6의 연락처 앱).
문서를 포함하여 주변을 검색했지만 사용자 지정 진동의 생성 또는 재생을 노출하는 공개 API를 찾을 수 없습니다. 가장 가까운 것은 AudioToolbox
프레임 워크 를 사용하여 짧고 일정한 진동을 재생하는 것입니다 .
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
커스텀 진동을위한 API가 있는지 아는 사람이 있습니까? 반드시 공용 API 일 필요는 없습니다. 연락처 앱이 무엇을 사용하는지 궁금합니다. 아는 사람 있나요?
PS Others는 ( 예 ) _CTServerConnectionCreate
에서 제안 했습니다 . 나는 그것을 시도했지만 어떤 이유로 든 진동이 발생하지 않았습니다.CoreTelephony
2015 년 10 월 업데이트 :
iOS 9에는 호환되는 장치에서 Taptic Engine과 상호 작용하는 새로운 비공개 API가 있습니다. 자세한 내용 은 iOS 9의 Taptic을 참조하십시오 .
연락처 앱에서 서비스 시간을 파헤친 후 어떻게 작동하는지 알아 냈습니다.
ABNewPersonViewControlle은 ToneLibrary 프레임 워크의 일부 클래스를 호출하여이를 수행합니다.
호출 스택은 다음과 같습니다.
0 CoreFoundation 0x3359a1d4 CFGetTypeID + 0
1 CoreFoundation 0x33596396 __CFPropertyListIsValidAux + 46
2 CoreFoundation 0x33517090 CFPropertyListCreateData + 124
3 AudioToolbox 0x38ac255a AudioServicesPlaySystemSoundWithVibration + 158
5 ToneLibrary 0x35a7811a -[TLVibrationRecorderView vibrationComponentDidStartForVibrationRecorderTouchSurface:] + 38
6 ToneLibrary 0x35a772b2 -[TLVibrationRecorderTouchSurface touchesBegan:withEvent:] + 342
7 UIKit 0x3610f526 -[UIWindow _sendTouchesForEvent:] + 314
8 UIKit 0x360fc804 -[UIApplication sendEvent:] + 376
웹에서 "AudioServicesPlaySystemSoundWithVibration"을 검색 한 후 아무것도 찾지 못했습니다.
그래서 직접 조사하기로 결정했습니다. AudioToolbox 프레임 워크의 개인 기능입니다.
함수의 선언은 다음과 같습니다.
void AudioServicesPlaySystemSoundWithVibration(SystemSoundID inSystemSoundID,id arg,NSDictionary* vibratePattern)
"inSystemSoundID"는 SystemSoundID입니다. "AudioServicesPlaySystemSound"와 마찬가지로 "kSystemSoundID_Vibrate"를 전달합니다.
"arg"는 중요하지 않습니다. nil을 전달하면 모든 것이 여전히 잘 작동합니다.
"vibratePattern" is a pointer of "NSDictionary", the Contact App pass into { Intensity = 1; OffDuration = 1; OnDuration = 10; } for recording user input.
But only call this function will make a vibration never stop. So I have to found some function to stop it.
The answer is "AudioServicesStopSystemSound". It's also a private function in AudioToolbox framework.
the declaration of the function is like
void AudioServicesStopSystemSound(SystemSoundID inSystemSoundID)
I guess the Contact App use AudioServicesPlaySystemSoundWithVibration in touchesBegan method, and AudioServicesStopSystemSound in touchEnd method to reach this effect.
TLVibrationController will manager a vibrate pattern object to record the process you input.
At last it generate a dictionary to pass into AudioServicesPlaySystemSoundWithVibration to replay the whole process like below:
NSMutableDictionary* dict = [NSMutableDictionary dictionary];
NSMutableArray* arr = [NSMutableArray array ];
[arr addObject:[NSNumber numberWithBool:YES]]; //vibrate for 2000ms
[arr addObject:[NSNumber numberWithInt:2000]];
[arr addObject:[NSNumber numberWithBool:NO]]; //stop for 1000ms
[arr addObject:[NSNumber numberWithInt:1000]];
[arr addObject:[NSNumber numberWithBool:YES]]; //vibrate for 1000ms
[arr addObject:[NSNumber numberWithInt:1000]];
[arr addObject:[NSNumber numberWithBool:NO]]; //stop for 500ms
[arr addObject:[NSNumber numberWithInt:500]];
[dict setObject:arr forKey:@"VibePattern"];
[dict setObject:[NSNumber numberWithInt:1] forKey:@"Intensity"];
AudioServicesPlaySystemSoundWithVibration(4095,nil,dict);
So if you want a custom vibrations in iOS. Use AudioServicesPlaySystemSoundWithVibration and AudioServicesStopSystemSound.
There's a project called HapticKeyboard that does this. See: http://code.google.com/p/zataangstuff/source/browse/trunk/HapticKeyboard/Classes/HapticKeyboard.m?r=93
Specifically, look at the last set of functions
_CTServerConnectionSetVibratorState(&x, connection, 0, 0, 0, 0, 0);
There are two problems:
- I doubt you'd get your app allowed into the app store. Apple will see this as a battery drain for users and they are pretty strict about the user experience
- This may require jailbreaking. There have been several new iOS versions since I've last played with this, so it's hard to tell
참고URL : https://stackoverflow.com/questions/12966467/are-there-apis-for-custom-vibrations-in-ios
'program story' 카테고리의 다른 글
문자열 리터럴 풀은 문자열 개체에 대한 참조 모음이거나 개체 모음입니다. (0) | 2020.11.05 |
---|---|
"필드에 불완전한 유형이 있습니다"오류 (0) | 2020.11.05 |
* args 구문을 사용하는 인수 목록에서 후행 쉼표가 SyntaxError 인 이유는 무엇입니까? (0) | 2020.11.05 |
Powershell ISE의 스크립트에 필요한 매개 변수를 전달하는 방법은 무엇입니까? (0) | 2020.11.05 |
Android 용 Firebug 또는 JavaScript 콘솔 디버그가 있습니까? (0) | 2020.11.05 |