@Jessica、あなたはそれを行うことはできません、bcosは制限されています。あなたのアプリケーションでそれを試してみたいのであれば、あなたのアプリはApp Storeで拒否されているかもしれません。
したがって、公開APIを使用することはできません。
あなたが見つけたリンクは、私的なAPIを使用していますが、これは文書化されていないか、期待通りに動作することが保証されています。プライベートAPIを呼び出したApp Storeアプリをリリースしようとすると、自動的に拒否されます。あなたが沈黙しているかどうか、確認したい場合は、コードの下に使用
、ビューコントローラでこの権利を宣言
-(BOOL)silenced {
#if TARGET_IPHONE_SIMULATOR
// return NO in simulator. Code causes crashes for some reason.
return NO;
#endif
CFStringRef state;
UInt32 propertySize = sizeof(CFStringRef);
AudioSessionInitialize(NULL, NULL, NULL, NULL);
AudioSessionGetProperty(kAudioSessionProperty_AudioRoute, &propertySize, &state);
if(CFStringGetLength(state) > 0)
return NO;
else
return YES;
}
For completeness, building off this link from Dan Bon, I implement the following method to solve this problem in my apps. One thing to note is that the code checks for the iPhone simulator first - executing the below code will crash the simulator. Anyone know why?
-(BOOL)silenced {
#if TARGET_IPHONE_SIMULATOR
// return NO in simulator. Code causes crashes for some reason.
return NO;
#endif
CFStringRef state;
UInt32 propertySize = sizeof(CFStringRef);
AudioSessionInitialize(NULL, NULL, NULL, NULL);
AudioSessionGetProperty(kAudioSessionProperty_AudioRoute, &propertySize, &state);
if(CFStringGetLength(state) > 0)
return NO;
else
return YES;
}
、あなたは単に
if ([self silenced]) {
NSLog(@"silenced");
else {
NSLog(@"not silenced");
}
Iをチェックしたいですこれがあなたに役立つと思います。 http://stackoverflow.com/questions/12725548/iphone-block-sms-using-xcoding-private-frameworks-whatever –