Skip to content

Commit ae80d69

Browse files
committed
fix: consider more cases, improve code
1 parent 39b7fc3 commit ae80d69

5 files changed

Lines changed: 42 additions & 12 deletions

File tree

MendixNative.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Pod::Spec.new do |s|
1414
s.source = { :git => "https://github.com/mendix/mendix-native.git", :tag => "#{s.version}" }
1515

1616
s.source_files = "ios/**/*.{h,m,mm,cpp,swift}"
17-
s.public_header_files = "ios/Modules/Helper/ReactHostHelper.h"
17+
s.public_header_files = ["ios/Modules/Helper/ReactHostHelper.h", "ios/Modules/NativeCookieModule/ObjCExceptionCatcher.h"]
1818
s.private_header_files = "ios/TurboModules/**/*.h"
1919

2020
s.dependency "SSZipArchive"

ios/Modules/Encryption/EncryptedStorage.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,15 @@ import Foundation
3333
kSecClass: kSecClassGenericPassword,
3434
kSecAttrAccount: key,
3535
kSecReturnData: kCFBooleanTrue as Any,
36-
kSecMatchLimit: kSecMatchLimitOne
36+
kSecMatchLimit: kSecMatchLimitOne,
37+
kSecUseAuthenticationUI: kSecUseAuthenticationUIFail
3738
] as CFDictionary
3839
var dataRef: CFTypeRef?
3940
let status = SecItemCopyMatching(query, &dataRef)
40-
if status == errSecSuccess {
41+
if status == errSecInteractionNotAllowed {
42+
// Device locked or item requires auth — don't delete, resolve as absent
43+
promise.resolve(NSNull())
44+
} else if status == errSecSuccess {
4145
guard let data = dataRef as? Data, let value = String(data: data, encoding: .utf8) else {
4246
promise.reject("An error occured while retrieving value", errorCode: Int(status))
4347
return
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#import <Foundation/Foundation.h>
2+
3+
NS_ASSUME_NONNULL_BEGIN
4+
5+
@interface ObjCExceptionCatcher : NSObject
6+
7+
/// Executes the block and returns its result. If an NSException is raised,
8+
/// catches it and returns nil instead of crashing.
9+
+ (nullable id)catchException:(id _Nullable (NS_NOESCAPE ^)(void))block;
10+
11+
@end
12+
13+
NS_ASSUME_NONNULL_END
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#import "ObjCExceptionCatcher.h"
2+
3+
@implementation ObjCExceptionCatcher
4+
5+
+ (nullable id)catchException:(id _Nullable (NS_NOESCAPE ^)(void))block {
6+
@try {
7+
return block();
8+
} @catch (NSException *exception) {
9+
NSLog(@"ObjCExceptionCatcher: caught %@%@", exception.name, exception.reason);
10+
return nil;
11+
}
12+
}
13+
14+
@end

ios/Modules/NativeCookieModule/SessionCookieStore.swift

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,20 +68,19 @@ public class SessionCookieStore {
6868
let status = SecItemCopyMatching(query as CFDictionary, &item)
6969

7070
if status == errSecInteractionNotAllowed {
71-
// Oversized/blocked item — remove so it never prompts again
72-
NSLog("SessionCookieStore: Blocked legacy item detected, clearing")
73-
clear(key: key)
71+
NSLog("SessionCookieStore: Item inaccessible (device locked), skipping restore")
7472
return nil
7573
} else if status == errSecSuccess, let data = item as? Data {
76-
do {
77-
let cookies = try NSKeyedUnarchiver.unarchivedObject(ofClasses: [NSArray.self, HTTPCookie.self], from: data) as? [HTTPCookie]
78-
return cookies
79-
} catch {
80-
// Unarchiving failed (corrupt/oversized blob) — self-heal by removing
81-
NSLog("SessionCookieStore: Failed to deserialize legacy cookies, clearing: \(error.localizedDescription)")
74+
let result = ObjCExceptionCatcher.catchException {
75+
try? NSKeyedUnarchiver.unarchivedObject(ofClasses: [NSArray.self, HTTPCookie.self], from: data)
76+
}
77+
78+
guard let cookies = result as? [HTTPCookie] else {
79+
NSLog("SessionCookieStore: Failed to deserialize cookies, clearing")
8280
clear(key: key)
8381
return nil
8482
}
83+
return cookies
8584
} else if status != errSecItemNotFound {
8685
// Any other unreadable state — delete to prevent repeated failures
8786
NSLog("SessionCookieStore: Unreadable legacy item (status: \(status)), clearing")

0 commit comments

Comments
 (0)