Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I mute incoming iPhone text messages programmatically?

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"];

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?

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.

like image 811
Jessica Avatar asked Apr 04 '12 17:04

Jessica


People also ask

Can you mute texts on iPhone?

Mute notifications for a conversationIn the Messages list, touch and hold a conversation. Tap Hide Alerts.

How do I silence my Messages?

For Android users, swipe down from the top of the screen twice to reveal the Quick connect menu, or tap the top of the screen twice. Click the 'Do not disturb' button to silence all calls, texts, notifications and alarms.

What happens when you mute a text conversation on iPhone?

Muting a conversation disables notifications from specific conversations.


1 Answers

@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.

So, Using public APIs, it is not possible.

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;

}

Declaring this right in the view controller, you'd simply check

if ([self silenced]) {
     NSLog(@"silenced");

else {
     NSLog(@"not silenced");
}
like image 74
Mehul Avatar answered Nov 15 '22 09:11

Mehul