Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The connection to service on pid 87 named * com.apple.commcenter.coretelephony.xpc was invalidated from this process #484

Closed
tachyon-ii opened this issue Oct 22, 2021 · 1 comment
Labels

Comments

@tachyon-ii
Copy link

Getting straight to the point this non fatal error message has a 1 line patch

diff --git a/PhoneNumberKit/PhoneNumberKit.swift b/PhoneNumberKit/PhoneNumberKit.swift
index 427e61b..33dcaa7 100644
--- a/PhoneNumberKit/PhoneNumberKit.swift
+++ b/PhoneNumberKit/PhoneNumberKit.swift
@@ -18,6 +18,7 @@ public final class PhoneNumberKit: NSObject {
     let metadataManager: MetadataManager
     let parseManager: ParseManager
     let regexManager = RegexManager()
+    let info = CTTelephonyNetworkInfo()
 
     // MARK: Lifecycle
 

Using XCode 13.0 and installing on an iPhone 11 running iOS 14.8

PhoneNumberKit repeatedly generates the following non fatal error message:

Updating selectors after delegate addition failed with: 
Error Domain=NSCocoaErrorDomain Code=4099 
"The connection to service on pid 87 named com.apple.commcenter.coretelephony.xpc 
was invalidated from this process." UserInfo={NSDebugDescription=
The connection to service on pid 87 named com.apple.commcenter.coretelephony.xpc 
was invalidated from this process.}

Repeatedly means 4 x for a view with 2 x phone fields.

Prior to using PhoneNumberKit I was directly accessing CoreTelephony to interrogate the serviceSubscriberCellularProviders to find the active carrier. The point being I was getting this "service on pid 87 error" and implemented a one line fix let info = CTTelephonyNetworkInfo() which (I assume) delays garbage collection sufficiently to prevent this error.

import Foundation
import CoreTelephony

class CountryCode {
    static let shared = CountryCode()

    /* The line below prevents this error
     *
     * [Client] Updating selectors after delegate addition failed with: 
     * Error Domain=NSCocoaErrorDomain Code=4099 
     * "The connection to service on pid 87 named com.apple.commcenter.coretelephony.xpc 
     * was invalidated from this process." UserInfo={NSDebugDescription=
     * The connection to service on pid 87 named com.apple.commcenter.coretelephony.xpc 
     * was invalidated from this process.}
     *
     */
    let info = CTTelephonyNetworkInfo()
    
    public func getCountryCode() -> String {
        guard let carriers = info.serviceSubscriberCellularProviders  else { return "" }
        // print(carriers)
        var isoCode : String = "us"
        for carrier in carriers {
            if carrier.value.isoCountryCode != nil {
                isoCode = carrier.value.isoCountryCode!
                break
            }
        }
        let prefixCodes = ["AF": "93", "AE": "971", "AL": "355", "AN": "599", "AS":"1", "AD": "376", "AO": "244", "AI": "1", "AG":"1", "AR": "54","AM": "374", "AW": "297", "AU":"61", "AT": "43","AZ": "994", "BS": "1", "BH":"973", "BF": "226","BI": "257", "BD": "880", "BB": "1", "BY": "375", "BE":"32","BZ": "501", "BJ": "229", "BM": "1", "BT":"975", "BA": "387", "BW": "267", "BR": "55", "BG": "359", "BO": "591", "BL": "590", "BN": "673", "CC": "61", "CD":"243","CI": "225", "KH":"855", "CM": "237", "CA": "1", "CV": "238", "KY":"345", "CF":"236", "CH": "41", "CL": "56", "CN":"86","CX": "61", "CO": "57", "KM": "269", "CG":"242", "CK": "682", "CR": "506", "CU":"53", "CY":"537","CZ": "420", "DE": "49", "DK": "45", "DJ":"253", "DM": "1", "DO": "1", "DZ": "213", "EC": "593", "EG":"20", "ER": "291", "EE":"372","ES": "34", "ET": "251", "FM": "691", "FK": "500", "FO": "298", "FJ": "679", "FI":"358", "FR": "33", "GB":"44", "GF": "594", "GA":"241", "GS": "500", "GM":"220", "GE":"995","GH":"233", "GI": "350", "GQ": "240", "GR": "30", "GG": "44", "GL": "299", "GD":"1", "GP": "590", "GU": "1", "GT": "502", "GN":"224","GW": "245", "GY": "595", "HT": "509", "HR": "385", "HN":"504", "HU": "36", "HK": "852", "IR": "98", "IM": "44", "IL": "972", "IO":"246", "IS": "354", "IN": "91", "ID":"62", "IQ":"964", "IE": "353","IT":"39", "JM":"1", "JP": "81", "JO": "962", "JE":"44", "KP": "850", "KR": "82","KZ":"77", "KE": "254", "KI": "686", "KW": "965", "KG":"996","KN":"1", "LC": "1", "LV": "371", "LB": "961", "LK":"94", "LS": "266", "LR":"231", "LI": "423", "LT": "370", "LU": "352", "LA": "856", "LY":"218", "MO": "853", "MK": "389", "MG":"261", "MW": "265", "MY": "60","MV": "960", "ML":"223", "MT": "356", "MH": "692", "MQ": "596", "MR":"222", "MU": "230", "MX": "52","MC": "377", "MN": "976", "ME": "382", "MP": "1", "MS": "1", "MA":"212", "MM": "95", "MF": "590", "MD":"373", "MZ": "258", "NA":"264", "NR":"674", "NP":"977", "NL": "31","NC": "687", "NZ":"64", "NI": "505", "NE": "227", "NG": "234", "NU":"683", "NF": "672", "NO": "47","OM": "968", "PK": "92", "PM": "508", "PW": "680", "PF": "689", "PA": "507", "PG":"675", "PY": "595", "PE": "51", "PH": "63", "PL":"48", "PN": "872","PT": "351", "PR": "1","PS": "970", "QA": "974", "RO":"40", "RE":"262", "RS": "381", "RU": "7", "RW": "250", "SM": "378", "SA":"966", "SN": "221", "SC": "248", "SL":"232","SG": "65", "SK": "421", "SI": "386", "SB":"677", "SH": "290", "SD": "249", "SR": "597","SZ": "268", "SE":"46", "SV": "503", "ST": "239","SO": "252", "SJ": "47", "SY":"963", "TW": "886", "TZ": "255", "TL": "670", "TD": "235", "TJ": "992", "TH": "66", "TG":"228", "TK": "690", "TO": "676", "TT": "1", "TN":"216","TR": "90", "TM": "993", "TC": "1", "TV":"688", "UG": "256", "UA": "380", "US": "1", "UY": "598","UZ": "998", "VA":"379", "VE":"58", "VN": "84", "VG": "1", "VI": "1","VC":"1", "VU":"678", "WS": "685", "WF": "681", "YE": "967", "YT": "262","ZA": "27" , "ZM": "260", "ZW":"263"]
        let countryDialingCode = prefixCodes[isoCode.uppercased()] ?? ""
        return countryDialingCode
    }
}
@github-actions
Copy link
Contributor

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale label Apr 23, 2022
bguidolim added a commit that referenced this issue May 4, 2022
…e issues (#521)

* Keeping a single reference of CTTelephonyNetworkInfo to avoid possible issues

This commit fix #444

Resources:
 - #484
 - https://stackoverflow.com/questions/14238586/coretelephony-crash
 - flurry/flurry-ios-sdk#200
 - amplitude/Amplitude-iOS#13

* Keeping only the real changes

Co-authored-by: Bruno Guidolim <bruno@pockid.com>
elijahheineman added a commit to EverlongProject/PhoneNumberKit that referenced this issue May 9, 2023
* bump tvOS support to 10, fix build issues

* Remove duplicate methods

Fix the bug that NSRange may cross the boundary

When working with text that’s presented to the user, use the localizedCaseInsensitiveCompare(_:) method instead.

Remove duplicate calls `setup`.

* remove nil value from carrier cellular provider

* 🔗 Callable URL and call() method to call on a device

* Update RegexManager.swift

Memory leak fixed on Charset fix and tested please add to next release

* Update CountryCodePickerViewController.swift

* Metadata updates for release 8.12.43

* Xcode: Update last upgrade check

* PhoneNumber: remove call method due to build issue when included in app extension

* Regex manager: fix build error with special character set

* Release 3.3.4

* Update flag after pasting/auto-filling a phone number

* Fix Swift 5.6 crash on Linux (#516)

* Replace use of NSMutableCharacterSet with CharacterSet

This change fixes a crash when initializing PhoneNumberKit on Linux

* Use designated constant for non-breaking space

* Create stale.yml

* Updated the compile time check to work with other platforms (#435)

* Metadata update: 8.12.47 (#519)

* Metadata update: 8.12.47

* Updated tests

Co-authored-by: Bruno Guidolim <bruno@pockid.com>

* Release 3.3.5

* Update stale.yml

* Adds accessibility text to country code button, (#439)

Makes Search bar input more explicit

Co-authored-by: Rebecca Chin <rchin@league.com>

* Added modalPresentationStyle Property (#436)

* Added modalPresentationStyle Property

* Fixed optional type to modalPresentationStyle

* Fixed Sample Project

* Fix bundle accessor for SwiftUI previews. (#485)

* Release 3.3.6

* Fix bundle acessor (#523)

* Fix #522

* Let's play safe

Co-authored-by: Bruno Guidolim <bruno@pockid.com>

* Keeping a single reference of CTTelephonyNetworkInfo to avoid possible issues (#521)

* Keeping a single reference of CTTelephonyNetworkInfo to avoid possible issues

This commit fix #444

Resources:
 - marmelroy/PhoneNumberKit#484
 - https://stackoverflow.com/questions/14238586/coretelephony-crash
 - flurry/flurry-ios-sdk#200
 - amplitude/Amplitude-iOS#13

* Keeping only the real changes

Co-authored-by: Bruno Guidolim <bruno@pockid.com>

* Release 3.3.7

* Introduce coding strategies for `PhoneNumber` (#517)

* Release 3.4.0

* Makes RegexManager thread-safe (#529)

* Fix #528

* Apply suggestions from code review

Co-authored-by: Michael Williams <michaeldwilliams@users.noreply.github.com>

Co-authored-by: Michael Williams <michaeldwilliams@users.noreply.github.com>

* Release 3.4.1

* Fix bundle search path (#531)

* Updated metadata and related unit-tests according to the v8.12.50 in Google library. (#534)

Please note: With the new metadata the partial formatter can add extra characters (like `(`) in the beginning of the string detection, if the default region is `US`. The Unit test changes in the `PartialFormatterTests` are highlighting those edge cases.

* Fix #249: Potential thread explosion (#535)

* Fix #249: Potential thread explosion

* Applying suggestion from code review

* Release 3.4.2

* Simplified `defaultRegionCode()` in `PhoneNumberKit` in order to handle better the multiple SIM related issues. (#538)

- The `CoreTelephony` based solution was replaced with a `Contacts` framework based one.
- Added more strict performance tests for parsing both via an array,. and through a non-optimized way (calling the `parse(_:_:)` method in the body of a for loop).

* Updated metadata according to 8.12.51. (#537)

* Release 3.4.3

* Normalizes the way of getting metadata from MetadataManager (#542)

* Release 3.4.4

* Updated metadata according to v8.12.52 https://github.com/google/libphonenumber/releases/tag/v8.12.52 (#545)

* Release 3.4.5

* Fix #451 no flag change for different regionCode (#550)

* Falling back default region to Locale if CNContactsUserDefaults is not available (fix #549) (#551)

* Metadata automation (#554)

* Started script to automate releases

* Added GH action

* Updated metadata to version metadata/8.12.53 (#555)

Co-authored-by: runner <runner@Mac-1660824613252.local>

* Release 3.4.6

* Stop testing metadata since it's supposed to change.

* Updated metadata to version metadata/8.12.54 (#556)

Co-authored-by: runner <runner@Mac-1661155838180.local>

* Release 3.4.7

* Fix #557 (#561)

* Revert #550 due issues with other countries (#562)

* Make sample app use local package

* Revert "Fix #451 no flag change for different regionCode (#550)"

This reverts commit d8c0069.

* Release 3.4.8

* Updated metadata to version metadata/8.12.55 (#568)

Co-authored-by: runner <runner@Mac-1662768069832.local>

* Release 3.4.9

* Updated metadata to version metadata/8.12.56 (#572)

Co-authored-by: runner <runner@Mac-1663934197792.local>

* Change references to ISO 639 language code into ISO 3166 region code (#571)

* Update flags for countries with the same international code (#563)

Fix #451

* Release 3.4.10

* Updated metadata to version metadata/8.12.57 (#576)

Co-authored-by: runner <runner@Mac-1665748767715.local>

* Fix macCatalyst OS bug if language is set to Korean (#578)

* Fix minor "dispaly" typo (#580)

* Updated metadata to version metadata/8.13.0 (#582)

Co-authored-by: runner <runner@Mac-1667735953427.local>

* Make sample app use the local package

* Introducing the new error `ambiguousNumber` (#583)

ParseManager now throws an error with a list of possible phone numbers in case a number was not able to be parsed and the guessing logic provides multiple phone numbers.

* Release 3.5.0

* Updated metadata to version metadata/8.13.1 (#586)

Co-authored-by: runner <runner@Mac-1669635957015.local>

* Release 3.5.1

* Updated metadata to version metadata/8.13.2 (#589)

Co-authored-by: runner <runner@Mac-1670500125558.local>

* Release 3.5.2

* Updated metadata to version metadata/8.13.3 (#590)

Co-authored-by: runner <runner@Mac-1671752828078.local>

* Add Equatable conformance for PhoneNumberError (#591)

* Change references to ISO 639 language code into ISO 3166 region code

* Add documentation for PhoneNumberError.ambiguousNumber

* Add Equatable conformance for PhoneNumberError

* Release 3.5.3

* Add missing text field delegate method (#592)

* Updated metadata to version metadata/8.13.4 (#594)

Co-authored-by: runner <runner@Mac-1673265644046.local>

* Release 3.5.4

* Only change default region if the withFlag is true (#593)

* Fix country picker by id (#601)

* Release 3.5.5

* Revert "Fix country picker by id (#601)" (#603)

This reverts commit eddc377.

Co-authored-by: Bruno Guidolim <bruno@ruuky.com>

* Updated metadata to version metadata/8.13.5 (#604)

Co-authored-by: runner <runner@Mac-1675092228380.local>

* Release 3.5.6

* Updated metadata to version metadata/8.13.6 (#605)

* Increment Swift version (#606)

* Release 3.5.7

* Updated metadata to version metadata/8.13.7 (#608)

* ensure country codes are capitalized per ISO specs (#612)

* Release 3.5.8

* Updated metadata to version metadata/8.13.8 (#617)

* Updated metadata to version metadata/8.13.9 (#624)

* Alternate way to load contents of a file in a Data object (#620)

* Updated metadata to version metadata/8.13.10 (#631)

* Updated metadata to version metadata/8.13.11 (#636)

Co-authored-by: runner <runner@Mac-1682595728106.local>

* Release 3.5.9

---------

Co-authored-by: Nicolas Degen <ndegen@me.com>
Co-authored-by: fuyoufang <fuyoufang@163.com>
Co-authored-by: Kevin CATHALY <alaknorth@gmail.com>
Co-authored-by: Ben Myers <benl.myers01@gmail.com>
Co-authored-by: sachithamh <5784803+sachithamh@users.noreply.github.com>
Co-authored-by: Horevoi Illia <illia.horevoi@materialise.kiev.ua>
Co-authored-by: Roy Marmelstein <marmelroy@gmail.com>
Co-authored-by: Roy Marmelstein <marmelroy@spotify.com>
Co-authored-by: Alessandro Mulloni <ale@mulloni.tech>
Co-authored-by: Bruno Guidolim <bguidolim@gmail.com>
Co-authored-by: David Roman <d@vidroman.dev>
Co-authored-by: Bobby Rohweder <BobbyRohweder@gmail.com>
Co-authored-by: Bruno Guidolim <bruno@pockid.com>
Co-authored-by: Rebecca Chin <rebeccagchin@gmail.com>
Co-authored-by: Rebecca Chin <rchin@league.com>
Co-authored-by: Erkam Kücet <ekucet@gmail.com>
Co-authored-by: Luke Redpath <luke@lukeredpath.co.uk>
Co-authored-by: Michael Williams <michaeldwilliams@users.noreply.github.com>
Co-authored-by: vladislavsosiuk <vladislavsosiuk@gmail.com>
Co-authored-by: Peter Molnar <petermolnar.hu@gmail.com>
Co-authored-by: Max <14940890+MaxZheleznyy@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: runner <runner@Mac-1660824613252.local>
Co-authored-by: runner <runner@Mac-1661155838180.local>
Co-authored-by: runner <runner@Mac-1662768069832.local>
Co-authored-by: runner <runner@Mac-1663934197792.local>
Co-authored-by: Iggy Drougge <idrougge@mac.com>
Co-authored-by: runner <runner@Mac-1665748767715.local>
Co-authored-by: jackyabcde <49716044+jackyabcde@users.noreply.github.com>
Co-authored-by: Greg <greg@vida.com>
Co-authored-by: runner <runner@Mac-1667735953427.local>
Co-authored-by: runner <runner@Mac-1669635957015.local>
Co-authored-by: runner <runner@Mac-1670500125558.local>
Co-authored-by: runner <runner@Mac-1671752828078.local>
Co-authored-by: Anna Strzeżek <astrzezek@gmail.com>
Co-authored-by: runner <runner@Mac-1673265644046.local>
Co-authored-by: Olivier Destrebecq <olivier@mobdesignapps.fr>
Co-authored-by: 4taras4 <4taras4@gmail.com>
Co-authored-by: Bruno Guidolim <bruno@ruuky.com>
Co-authored-by: runner <runner@Mac-1675092228380.local>
Co-authored-by: Juantri94 <55553750+Juantri94@users.noreply.github.com>
Co-authored-by: Morgan Dock <mmdock@users.noreply.github.com>
Co-authored-by: runner <runner@Mac-1682595728106.local>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant