如何以编程方式静音传入的iPhone短信? [英] How can I mute incoming iPhone text messages programmatically?

查看:123
本文介绍了如何以编程方式静音传入的iPhone短信?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试使用AVSystemController私有框架根据​​用户的选择使系统噪音静音.我目前正在通过以下方式屏蔽电话:[(AVSystemController object) setVolumeTo:0.0 forCategory:@"Ringtone"];

I'm currently trying to use the AVSystemController private framework to mute system noises based on the user's selection. I'm currently muting phone calls by calling: [(AVSystemController object) setVolumeTo:0.0 forCategory:@"Ringtone"];

是否有命令对收到的短信执行此操作?我想这将基于该调用中标识的类别的更改.但是,我找不到要参考的类别列表.我能够找到的10个(Alert, Audio/Video, Ringtone, Voicemail, VoicemailGreeting, PhoneCall, TTYCall, RingtonePreview, Alarm, Record)中,没有一个控制文本消息的声音.有一个类别可以做到这一点吗?如果没有,还有其他方法可以使传入文本中的声音静音吗?

Is there a command to do that for incoming text messages? I imagine it would be based on a change in the category identified in that call. However, I can't find a list of categories to reference. Of the 10 I've been able to find (Alert, Audio/Video, Ringtone, Voicemail, VoicemailGreeting, PhoneCall, TTYCall, RingtonePreview, Alarm, Record), none of them govern text message sounds. Is there a category to do this? If not, is there any other way to mute the sound from incoming texts?

我意识到这违反了苹果公司的禁止私有框架"政策,但是该应用程序不会在应用商店中上架,所以这没问题.我正在使用最新版本的Xcode和最新版本的IOS进行开发,因此任何实现此目的的方法都是可行的.

I realize this goes against Apple's no-private-frameworks policy, but this app won't go up on the app store so that's no problem. I'm developing it using the latest version of Xcode for the latest version of IOS, so any method to accomplish this would be doable.

推荐答案

@Jessica,您不能这样做,因为它是受限制的.如果您想在应用程序中尝试它,则您的应用程序可能会在应用商店中被拒绝.

@Jessica, You can't do that, bcos it's restricted. if you want to try it in your application, then your app might be Rejected in App store.

因此,不可能使用公共API.

So, Using public APIs, it is not possible.

您找到的链接使用的是私有API,没有记录或保证这些API可以按您期望的方式工作.如果您尝试发布一个调用私有API的App Store应用,则会被自动拒绝.

The link you found is using private APIs, which aren't documented or guaranteed to work the way you'd expect. If you tried to release an App Store app that called a private API, it would be automatically rejected.

如果要检查,是否静音,请使用下面的代码,

if you want to Check , whether is silent or not, then use below code,

    -(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");
}

这篇关于如何以编程方式静音传入的iPhone短信?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆