Jes*_*ica 7 iphone sms xcode system-sounds
我目前正在尝试使用AVSystemController私有框架根据用户的选择来静音系统噪音.我正打电话给我打电话:[(AVSystemController object) setVolumeTo:0.0 forCategory:@"Ringtone"];
是否有命令为传入的短信执行此操作?我想这将基于该呼叫中确定的类别的变化.但是,我找不到要引用的类别列表.在我能找到的10个中(Alert, Audio/Video, Ringtone, Voicemail, VoicemailGreeting, PhoneCall, TTYCall, RingtonePreview, Alarm, Record),没有一个能够控制短信的声音.有这样的类别吗?如果没有,是否还有其他方法可以将传入文本中的声音静音?
我意识到这违反了Apple的非私有框架政策,但这个应用程序不会在应用程序商店上升,所以这没问题.我正在使用最新版本的XOS为最新版本的IOS开发它,所以任何实现这一目标的方法都是可行的.
@Jessica,你不能这样做,因为它受到限制。如果您想在您的应用程序中尝试它,那么您的应用程序可能会在应用程序商店中被拒绝。
因此,使用公共 API 是不可能的。
您找到的链接使用的是私有 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;
}
Run Code Online (Sandbox Code Playgroud)
在视图控制器中声明这一点,您只需检查
if ([self silenced]) {
NSLog(@"silenced");
else {
NSLog(@"not silenced");
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2290 次 |
| 最近记录: |