Skip to content

Commit 8f42fdd

Browse files
author
“Akshay
committed
[MOB-9247] - Bug fix for no push on APNS SANDBOX
Logic explanation SDK checks if the target is a simulator if so > APNS SANDBOX if not > read the file 'embedded.provision' Check if certain value exist to mark it as APNSSANDBOX If not, default it to PRODUCTION APNS. Using Xcode 16 beta with iOS 18 beta, we discovered that file reading was failing with normal ASCII encoding. Diff explanation - File was able to type to data easily. Once the data was available, now we try to read the file with all encoding available to us now. If none of them works, we print ITBLError. The first one to decode the file proceeds with scan operation - finding the right tags and keywords. - Tested with Xcode GA and Beta and iOS 17 and iOS 18 devices
1 parent a78eea7 commit 8f42fdd

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

swift-sdk/Internal/APNSTypeChecker.swift

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,39 @@ struct APNSTypeChecker: APNSTypeCheckerProtocol {
5959
}
6060

6161
static func readMobileProvision(fromPath path: String) -> [AnyHashable: Any] {
62-
guard let asciiString = try? String(contentsOfFile: path, encoding: .ascii) else {
62+
guard let data = try? Data(contentsOf: URL(fileURLWithPath: path)) else {
6363
ITBError("Could not read file: \(path)")
6464
return [:]
6565
}
66+
67+
let encodings: [String.Encoding] = [
68+
.ascii,
69+
.utf8,
70+
.utf16,
71+
.utf16BigEndian,
72+
.utf16LittleEndian,
73+
.utf32,
74+
.utf32BigEndian,
75+
.utf32LittleEndian,
76+
.isoLatin1,
77+
.macOSRoman
78+
]
79+
80+
var asciiString: String?
81+
82+
for encoding in encodings {
83+
if let string = String(data: data, encoding: encoding) {
84+
asciiString = string
85+
break
86+
}
87+
}
88+
89+
guard let finalString = asciiString else {
90+
ITBError("Failed to detect APNS type from provisioning file. Defaulting to type - Production. Please use IterableConfig.pushPlatform to manually set APNS platform type")
91+
return [:]
92+
}
6693

67-
guard let propertyListString = scan(string: asciiString, begin: "<plist", end: "</plist>") else {
94+
guard let propertyListString = scan(string: finalString, begin: "<plist", end: "</plist>") else {
6895
return [:]
6996
}
7097

0 commit comments

Comments
 (0)