iosswiftswiftuicallkitcallblocking

How to open Call Blocking & Identification in settings from my App iOS


I am using ios 14 and want to open call blocking and identification from my app on button press. For this purpose i am using the below code

import SwiftUI
import CallKit

struct ContentView: View {
    var body: some View {
        VStack {
            Button(action: openCallerIDSettings) {
                Text("Open Caller ID Settings")
                    .padding()
                    .background(Color.blue)
                    .foregroundColor(.white)
                    .cornerRadius(8)
            }
        }
    }
    private func openCallerIDSettings() {
        CXCallDirectoryManager.sharedInstance.openSettings { err in
            print(";;;",err as Any)
        }
    }
}

But its only opening the main Phone Settings . I want to open Call Blocking & Identification, I have already tried different methods like using App-prefs method

private func openCallerIDSettings() {
        if let url = URL(string: "App-prefs:Phone&path=CLASSIFICATION_AND_REPORTING") {
            if UIApplication.shared.canOpenURL(url) {
                UIApplication.shared.open(url, options: [:], completionHandler: nil)
            }
        }
    }

but couldn't find the exact string for Call Blocking & Identification


Solution

  • The openSettings function that you have in your first code block is the official method to open the call blocking settings.

    Preferences urls are considered private api and using them will lead to rejection during app review.

    I note that the documentation for openSettings states that it

    Opens the iOS Settings app and shows the Call Blocking & Identification settings.

    However, in my testing I found that it only opens the Call Blocking & Identification page if the Settings app is already in the "Phone" settings page. If it is not then it opens the Phone settings page.

    I noticed that TrueCaller does seem to go to the phone settings page and then Call Blocking & Identification. Perhaps they are risking using a private api.

    This seems like it is a bug or at least a variation from the documented behaviour.

    You could open a tech support incident or log a bug with Apple as it seems that this function is not behaving as documented.

    If you can reproduce this behaviour in an iOS 18 beta then you can also log beta feedback. In my experience the beta process is a good opportunity to get issues addressed.

    Meanwhile, you might consider providing instructions to the user to go to “call blocking and identification” before opening the settings screen.