iOS Question Detect if iPhone has caller ID barring on

JackKirk

Well-Known Member
Licensed User
Longtime User
As a follow on to:

https://www.b4x.com/android/forum/threads/problem-overriding-caller-id-barring.63410/

If you can not override caller ID barring can you at least detect whether it is on or not (and then send a message to user etc).

I'm guessing it might be in iPhone library under Settings:

https://www.b4x.com/b4i/help/iphone.html#settings

But this is extremely cryptic and says "See the settings tutorial for more information" - and a search gave me no hits on an iPhone settings tutorial.

Or maybe this is a NativeObject exercise?

Some help would really be appreciated...
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
But this is extremely cryptic and says "See the settings tutorial for more information" - and a search gave me no hits on an iPhone settings tutorial.
See the first search result: https://www.b4x.com/android/forum/pages/results/?query=b4i+settings

f you can not override call barring can you at least detect whether it is on or not (and then send a message to user etc).
I don't think that it is possible. If you find any swift or objective c code that does it then I can help you translate it.
 
Upvote 0

JackKirk

Well-Known Member
Licensed User
Longtime User
Erel,

OK looks like iPhone.Settings is not relevant to detecting caller ID barring - thanks for this link though as user preferences/settings is the next item on the agenda of my B4I app.

I will start Googling for some low level code to detect caller ID barring.

You say Swift - I was under the impression that you just did #if OBJC ... - or am I really displaying my ignorance?

Regards...
 
Last edited:
Upvote 0

JackKirk

Well-Known Member
Licensed User
Longtime User
Well I spent a couple of hours Googling to no avail - it appears to be totally impossible to programmatically get iOS/iPhone system settings - it appears to be impossible to even programmatically open the settings app to anything but the host app's settings.

Only 2 things of value came out of it:
  • I have a better appreciation of just what a swamp iOS is - and Tim Cook had the hide to say Android is a “toxic hellstew of vulnerabilities”.
  • I realised I should have been more precise with my verbage - I should have been asking about "caller ID barring" not "call barring" - and have edited titles and contents of my recent relevant posts to suit.
 
Upvote 0

BillMeyer

Well-Known Member
Licensed User
Longtime User
Is this perhaps what you are looking for:


B4X:
#If OBJC

//
  // CXCallDirectoryProvider.h
  // CallKit
  //
  // Copyright © 2016 Apple. All rights reserved.
  //

  @available (iOS 10.0, *)
  public class CXCallDirectoryProvider: NSObject, NSExtensionRequestHandling {

  public func beginRequest (with context: CXCallDirectoryExtensionContext )
  }}

   //
  // CXCallDirectoryExtensionContext.h
  // CallKit
  //
  // Copyright © 2016 Apple. All rights reserved.
  // //

  @available (iOS 10.0, *)
  public class CXCallDirectoryExtensionContext: NSExtensionContext {
 
  public func addBlockingEntry (withNextSequentialPhoneNumber phoneNumber: String )
 
  public func addIdentificationEntry (withNextSequentialPhoneNumber phoneNumber: String , label: String)
 
  public func completeRequest (completionHandler completion: ( (Bool) -> Swift Void) = nil.?)
  }}
  import Foundation
  import CallKit

  class CallDirectoryHandler: CXCallDirectoryProvider {

  override func beginRequest (with context: CXCallDirectoryExtensionContext ) {
  // --- 1
  guard let phoneNumbersToBlock = retrievePhoneNumbersToBlock () else {
  NSLog ( "Unable to retrieve phone numbers to block")
  let error = NSError (domain: " CallDirectoryHandler", code: 1, userInfo: nil)
  Context.cancelRequest (withError: error)
  Return
  }}
     
  // --- 2
  for phoneNumber in phoneNumbersToBlock {
  Context.addBlockingEntry (withNextSequentialPhoneNumber: phoneNumber)
  }}
     
  // --- 3
  guard let (phoneNumbersToIdentify, phoneNumberIdentificationLabels) = retrievePhoneNumbersToIdentifyAndLabels () else {
  NSLog ( "Unable to retrieve phone numbers to identify and their labels")
  let error = NSError (domain: " CallDirectoryHandler", code: 2, userInfo: nil)
  Context.cancelRequest (withError: error)
  Return
  }}
     
  // --- 4
  for (phoneNumber, label) in zip (phoneNumbersToIdentify, phoneNumberIdentificationLabels) {
  Context.addIdentificationEntry (withNextSequentialPhoneNumber: phoneNumber, label: label)
  }}
     
  // --- 5
  Context.completeRequest ()
  }}
 
  private func retrievePhoneNumbersToBlock () -> [ String] {?
  // retrieve list of phone numbers to block
  return [ "+ 8618xxxx157"]
  }}
 
  private func retrievePhoneNumbersToIdentifyAndLabels () -> ( phoneNumbers: [String], labels: [String]) {?
  // retrieve list of phone numbers to identify, and their labels
  return ([ "+ 8618xxxx569"] , [ " Test"])
  }}
 
  }}

#End if

Perhaps Erel can help to translate it - Thanks !! (Post #2)
 
Upvote 0

JackKirk

Well-Known Member
Licensed User
Longtime User
This looks more like code to manage blocking of incoming calls rather than detect whether the phone has caller ID barring turned on for outgoing calls.

However I'd be very interested in what Erel or someone of similar skills makes of it.

Does:

@available (iOS 10.0, *)

mean this would only work on the most recent iPhones?
 
Last edited:
Upvote 0
Top