Objective-C Runtime

RSS for tag

The Objective-C runtime is a runtime library that supports the dynamic properties of the Objective-C language.

Posts under Objective-C Runtime tag

88 Posts

Post

Replies

Boosts

Views

Activity

Crash "KVO_IS_RETAINING_ALL_OBSERVERS_OF_THIS_OBJECT_IF_IT_CRASHES_AN_OBSERVER_WAS_OVERRELEASED_OR_SMASHED"
Hello, I'm trying to address the following crash from an old Objective-C code. Crashed: com.apple.main-thread 0 libobjc.A.dylib 0x88e8 object_isClass + 16 1 Foundation 0x1d748 KVO_IS_RETAINING_ALL_OBSERVERS_OF_THIS_OBJECT_IF_IT_CRASHES_AN_OBSERVER_WAS_OVERRELEASED_OR_SMASHED + 48 2 Foundation 0x2be10 -[NSObject(NSKeyValueObservingPrivate) _changeValueForKeys:count:maybeOldValuesDict:maybeNewValuesDict:usingBlock:] + 284 3 Foundation 0x21c5c -[NSObject(NSKeyValueObservingPrivate) _changeValueForKey:key:key:usingBlock:] + 72 4 Foundation 0x2daf8 _NSSetBoolValueAndNotify + 316 5 SDKCore 0x47854 __45-[CameraSession processPhoto:orientation:]_block_invoke_3 + 239 (CameraSession.m:239) 6 libdispatch.dylib 0x2914 _dispatch_call_block_and_release + 32 7 libdispatch.dylib 0x4660 _dispatch_client_callout + 20 8 libdispatch.dylib 0x12b60 _dispatch_main_queue_callback_4CF + 944 9 CoreFoundation 0x51cd4 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 16 10 CoreFoundation 0xbeac __CFRunLoopRun + 2540 11 CoreFoundation 0x1f3b8 CFRunLoopRunSpecific + 600 12 GraphicsServices 0x138c GSEventRunModal + 164 13 UIKitCore 0x5196a8 -[UIApplication _run] + 1100 14 UIKitCore 0x2987f4 UIApplicationMain + 2092 15 MyApp 0x79bc main + 11 (main.swift:11) 16 ??? 0x102161a24 (Missing) The crash is due to setting takingPhoto to NO in - (void)processPhoto:(AVCapturePhoto *)photo orientation:(UIDeviceOrientation)orientation. From what I understand, the crash would be caused by a released observer receiving the notification, but I don't see how it's possible given the following code (this is an excerpt with relevant parts). @implementation CameraSession @synthesize takingPhoto = _takingPhoto; - (void)dealloc { [self _cleanupObservers]; } - (instancetype)init { self = [super init]; if (self) { [self _setupObservers]; } return self; } - (void)setTakingPhoto:(BOOL)takingPhoto { if (!takingPhoto) { [self.triggerDecider reset]; } _takingPhoto = takingPhoto; } - (BOOL)isTakingPhoto { return _takingPhoto; } - (void)takePhoto { if (self.isTakingPhoto) { return; } self.takingPhoto = YES; // … [self.capturePhotoOutput capturePhotoWithSettings:[self buildCapturePhotoSettings] delegate:self]; } - (void)processPhoto:(AVCapturePhoto *)photo orientation:(UIDeviceOrientation)orientation { dispatch_async(self.captureSessionQueue, ^{ [self.delegate cameraSessionDidSnapPhoto:self]; [self.cameraCaptureHandler processPhoto:photo orientation:orientation onSuccess:^(Scan *scan) { dispatch_async(dispatch_get_main_queue(), ^{ self.takingPhoto = NO; [self.delegate cameraSession:self didGenerateScan:scan]; }); } failure:^(NSError *error) { self.takingPhoto = NO; [self.delegate cameraSession:self didFailToSnapPhotoWithError:error]; }]; }); } #pragma mark - KVO - (void)_setupObservers { [self addObserver:self forKeyPath:@"takingPhoto" options:NSKeyValueObservingOptionInitial|NSKeyValueObservingOptionNew context:CameraSessionKVOContext]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(captureSessionRuntimeError:) name:AVCaptureSessionRuntimeErrorNotification object:self.captureSession]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(captureSessionDidStartRunning:) name:AVCaptureSessionDidStartRunningNotification object:self.captureSession]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(captureSessionDidStopRunning:) name:AVCaptureSessionDidStopRunningNotification object:self.captureSession]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(captureSessionWasInterrupted:) name:AVCaptureSessionWasInterruptedNotification object:self.captureSession]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(captureSessionInterruptionEnded:) name:AVCaptureSessionInterruptionEndedNotification object:self.captureSession]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidEnterBackground) name:UIApplicationDidEnterBackgroundNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillEnterForeground) name:UIApplicationWillEnterForegroundNotification object:nil]; } - (void)_cleanupObservers { [self removeObserver:self forKeyPath:@"takingPhoto" context:CameraSessionKVOContext]; [[NSNotificationCenter defaultCenter] removeObserver:self]; } - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *,id> *)change context:(void *)context { if (context == CameraSessionKVOContext) { if (object == self && [keyPath isEqualToString:@"takingPhoto"]) { // While taking the photo, stop processing video frames // ... } } else { [super observeValueForKeyPath:keyPath ofObject:object change:change context:context]; } } @end Am I missing something here? Thanks! Bruno
1
0
1.7k
Dec ’21
Register Template causes crash issue when launching app
Hi all, I am experiencing crash issue when my app is trying to register the device for notification function. It runs well on a iphone 6 device with ios 11, but this line of code crashes on a newer iphone model with latest ios 15. self.hub registerTemplateWithDeviceToken:sharedManager.pushTokenData name:@"myTemplate" jsonBodyTemplate:template expiryTemplate:nil tags:tagSet completion:^(NSError *error) Have anyone of you encountered similar issue before? Or is it possible that there is some configuration settings I may left out in XCode? Thanks a lot in advance.
2
0
782
Nov ’21
iOS15 show you don’t have permission to access “Caches” with Newstand download
my app is newsstand app. it is success download issue in my app with iOS14 & iOS15 simulate. when i try on real device, it fail to download. log Error Domain=NSCocoaErrorDomain Code=513 "“1318303744724624100” couldn’t be moved because you don’t have permission to access “Caches”." UserInfo={NSSourceFilePathErrorKey=/var/mobile/Media/Downloads/7803184277104936561/1318303744724624100, NSUserStringVariant=(   Move ), NSDestinationFilePath=/private/var/mobile/Containers/Data/Application/1C6FE6AF-1670-48ED-BE04-2806C8AECC65/Library/Caches/bgdl-4119-6c4a7ac1c9c0c671.xzip, NSFilePath=/var/mobile/Media/Downloads/7803184277104936561/1318303744724624100, NSUnderlyingError=0x282aa3d80 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}} i have set Privacy - Downloads Folder Usage Description in info.plist please help
9
0
3.7k
Oct ’21
Variable not captured unless referencing explicitly from local assignment
I'm trying to modify a shared __block BOOL variable for the purposes of flagging of execution to proceed. I implemented it successfully by creating an object that encapsulates the BOOL variable, but when sending the block inline, there are issues--I must create a local variable for the block and explicitly reference the BOOL variable inside of it (marked 1A in code sample). Any ideas how to make the - (void)primitive_cancellable_dispatch_after:(dispatch_time_t)delay block:(MyBlock)block stop:(BOOL*)stop method work without this requirement from the call site? It seems that the variable is not being captured unless it is being assigned locally and referenced. In general, at what point is the variable captured if not being explicitly referenced locally? dispatch_time_t delay = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)); __block BOOL stop; // =============== 1A =============== MyBlock primitiveBlock = ^{ NSLog(@"Ran primitive implementation via assignment. (stop: %@ / %p)", @(stop), &stop); // stop only "captured" when referencing within a locally assigned block, if this line is commented out, stop isn't updated }; // =============== 1A =============== [self primitive_cancellable_dispatch_after:delay block:^{ NSLog(@"Ran primitive implementation via inline. (stop: %@ / %p)", @(stop), &stop); } stop:&stop]; __block Task *task = [self reference_cancellable_dispatch_after:delay block:^{ NSLog(@"Ran reference implementation: (task.shouldCancel: %@)",@(task.shouldCancel)); }]; task.shouldCancel = NO; // works as expected stop = NO; // stop isn't updated as expected, when checking value within "primitive_cancellable_dispatch_after", always returns no } - (void)primitive_cancellable_dispatch_after:(dispatch_time_t)delay block:(MyBlock)block stop:(BOOL*)stop { dispatch_after(delay, dispatch_get_main_queue(), ^{ BOOL shouldStop = *stop; // stop doesn't seem to resolving correctly, stop is always "NO", unless assigning a local block outside NSLog(@"Checking primitive stop (shouldStop: %@ / %p)", @(shouldStop), stop); if(!shouldStop && block) { block(); NSLog(@"Checking primitive stop (shouldStop: %@ / %p)", @(shouldStop), stop); } }); } /*@interface Task : NSObject @property (nonatomic, assign) BOOL shouldCancel; @property (nonatomic, strong) Task *task; @end @implementation Task @end*/ - (Task*)reference_cancellable_dispatch_after:(dispatch_time_t)delay block:(MyBlock)block { Task *task = [Task new]; dispatch_after(delay, dispatch_get_main_queue(), ^{ if(!task.shouldCancel && block) { block(); } }); return task; }
9
0
2.2k
Jun ’21
Load dylibs signed by different team
Hello again. We have a sandboxed app in macOS App Store. It has to load dylib files using dlopen(). The dylib files are signed by our vendor. When the app tries to load them, we see this error similar to "mapping process and mapped file have different Team IDs". We tried adding disable-library-validation but when we do so, the app refuses even to start. Is there a way to achieve loading of dylibs signed by another team? Also, this issue happens with only a few users. I don't see this issue on my development machines.
4
0
2.9k
Jun ’21
Crash "KVO_IS_RETAINING_ALL_OBSERVERS_OF_THIS_OBJECT_IF_IT_CRASHES_AN_OBSERVER_WAS_OVERRELEASED_OR_SMASHED"
Hello, I'm trying to address the following crash from an old Objective-C code. Crashed: com.apple.main-thread 0 libobjc.A.dylib 0x88e8 object_isClass + 16 1 Foundation 0x1d748 KVO_IS_RETAINING_ALL_OBSERVERS_OF_THIS_OBJECT_IF_IT_CRASHES_AN_OBSERVER_WAS_OVERRELEASED_OR_SMASHED + 48 2 Foundation 0x2be10 -[NSObject(NSKeyValueObservingPrivate) _changeValueForKeys:count:maybeOldValuesDict:maybeNewValuesDict:usingBlock:] + 284 3 Foundation 0x21c5c -[NSObject(NSKeyValueObservingPrivate) _changeValueForKey:key:key:usingBlock:] + 72 4 Foundation 0x2daf8 _NSSetBoolValueAndNotify + 316 5 SDKCore 0x47854 __45-[CameraSession processPhoto:orientation:]_block_invoke_3 + 239 (CameraSession.m:239) 6 libdispatch.dylib 0x2914 _dispatch_call_block_and_release + 32 7 libdispatch.dylib 0x4660 _dispatch_client_callout + 20 8 libdispatch.dylib 0x12b60 _dispatch_main_queue_callback_4CF + 944 9 CoreFoundation 0x51cd4 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 16 10 CoreFoundation 0xbeac __CFRunLoopRun + 2540 11 CoreFoundation 0x1f3b8 CFRunLoopRunSpecific + 600 12 GraphicsServices 0x138c GSEventRunModal + 164 13 UIKitCore 0x5196a8 -[UIApplication _run] + 1100 14 UIKitCore 0x2987f4 UIApplicationMain + 2092 15 MyApp 0x79bc main + 11 (main.swift:11) 16 ??? 0x102161a24 (Missing) The crash is due to setting takingPhoto to NO in - (void)processPhoto:(AVCapturePhoto *)photo orientation:(UIDeviceOrientation)orientation. From what I understand, the crash would be caused by a released observer receiving the notification, but I don't see how it's possible given the following code (this is an excerpt with relevant parts). @implementation CameraSession @synthesize takingPhoto = _takingPhoto; - (void)dealloc { [self _cleanupObservers]; } - (instancetype)init { self = [super init]; if (self) { [self _setupObservers]; } return self; } - (void)setTakingPhoto:(BOOL)takingPhoto { if (!takingPhoto) { [self.triggerDecider reset]; } _takingPhoto = takingPhoto; } - (BOOL)isTakingPhoto { return _takingPhoto; } - (void)takePhoto { if (self.isTakingPhoto) { return; } self.takingPhoto = YES; // … [self.capturePhotoOutput capturePhotoWithSettings:[self buildCapturePhotoSettings] delegate:self]; } - (void)processPhoto:(AVCapturePhoto *)photo orientation:(UIDeviceOrientation)orientation { dispatch_async(self.captureSessionQueue, ^{ [self.delegate cameraSessionDidSnapPhoto:self]; [self.cameraCaptureHandler processPhoto:photo orientation:orientation onSuccess:^(Scan *scan) { dispatch_async(dispatch_get_main_queue(), ^{ self.takingPhoto = NO; [self.delegate cameraSession:self didGenerateScan:scan]; }); } failure:^(NSError *error) { self.takingPhoto = NO; [self.delegate cameraSession:self didFailToSnapPhotoWithError:error]; }]; }); } #pragma mark - KVO - (void)_setupObservers { [self addObserver:self forKeyPath:@"takingPhoto" options:NSKeyValueObservingOptionInitial|NSKeyValueObservingOptionNew context:CameraSessionKVOContext]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(captureSessionRuntimeError:) name:AVCaptureSessionRuntimeErrorNotification object:self.captureSession]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(captureSessionDidStartRunning:) name:AVCaptureSessionDidStartRunningNotification object:self.captureSession]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(captureSessionDidStopRunning:) name:AVCaptureSessionDidStopRunningNotification object:self.captureSession]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(captureSessionWasInterrupted:) name:AVCaptureSessionWasInterruptedNotification object:self.captureSession]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(captureSessionInterruptionEnded:) name:AVCaptureSessionInterruptionEndedNotification object:self.captureSession]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidEnterBackground) name:UIApplicationDidEnterBackgroundNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillEnterForeground) name:UIApplicationWillEnterForegroundNotification object:nil]; } - (void)_cleanupObservers { [self removeObserver:self forKeyPath:@"takingPhoto" context:CameraSessionKVOContext]; [[NSNotificationCenter defaultCenter] removeObserver:self]; } - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *,id> *)change context:(void *)context { if (context == CameraSessionKVOContext) { if (object == self && [keyPath isEqualToString:@"takingPhoto"]) { // While taking the photo, stop processing video frames // ... } } else { [super observeValueForKeyPath:keyPath ofObject:object change:change context:context]; } } @end Am I missing something here? Thanks! Bruno
Replies
1
Boosts
0
Views
1.7k
Activity
Dec ’21
Register Template causes crash issue when launching app
Hi all, I am experiencing crash issue when my app is trying to register the device for notification function. It runs well on a iphone 6 device with ios 11, but this line of code crashes on a newer iphone model with latest ios 15. self.hub registerTemplateWithDeviceToken:sharedManager.pushTokenData name:@"myTemplate" jsonBodyTemplate:template expiryTemplate:nil tags:tagSet completion:^(NSError *error) Have anyone of you encountered similar issue before? Or is it possible that there is some configuration settings I may left out in XCode? Thanks a lot in advance.
Replies
2
Boosts
0
Views
782
Activity
Nov ’21
iOS15 show you don’t have permission to access “Caches” with Newstand download
my app is newsstand app. it is success download issue in my app with iOS14 & iOS15 simulate. when i try on real device, it fail to download. log Error Domain=NSCocoaErrorDomain Code=513 "“1318303744724624100” couldn’t be moved because you don’t have permission to access “Caches”." UserInfo={NSSourceFilePathErrorKey=/var/mobile/Media/Downloads/7803184277104936561/1318303744724624100, NSUserStringVariant=(   Move ), NSDestinationFilePath=/private/var/mobile/Containers/Data/Application/1C6FE6AF-1670-48ED-BE04-2806C8AECC65/Library/Caches/bgdl-4119-6c4a7ac1c9c0c671.xzip, NSFilePath=/var/mobile/Media/Downloads/7803184277104936561/1318303744724624100, NSUnderlyingError=0x282aa3d80 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}} i have set Privacy - Downloads Folder Usage Description in info.plist please help
Replies
9
Boosts
0
Views
3.7k
Activity
Oct ’21
APP terminated in background also auto reload
When my app is terminate in background, I found the class's + (void)load method called before I relaunch or bring it to foreground.
Replies
1
Boosts
0
Views
1.3k
Activity
Oct ’21
undefined symbols OBJC_CLASS$_FIRAnalytics ios
steps to reproduce 1.open xcode ios 1.create framework(not static) 2.included firebase frameworks 3.build framework success 4.added dynamic framework in project trying to build but getting compilation errors
Replies
0
Boosts
0
Views
1k
Activity
Jul ’21
undefined symbols
Showing Recent Messages Undefined symbol: OBJC_CLASS$_FIRAnalytics steps to reproduce create dynamic framework included firebase frameworks build framework success added dynamic framework in project trying to build but getting compilation errors
Replies
0
Boosts
0
Views
1.2k
Activity
Jul ’21
Variable not captured unless referencing explicitly from local assignment
I'm trying to modify a shared __block BOOL variable for the purposes of flagging of execution to proceed. I implemented it successfully by creating an object that encapsulates the BOOL variable, but when sending the block inline, there are issues--I must create a local variable for the block and explicitly reference the BOOL variable inside of it (marked 1A in code sample). Any ideas how to make the - (void)primitive_cancellable_dispatch_after:(dispatch_time_t)delay block:(MyBlock)block stop:(BOOL*)stop method work without this requirement from the call site? It seems that the variable is not being captured unless it is being assigned locally and referenced. In general, at what point is the variable captured if not being explicitly referenced locally? dispatch_time_t delay = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)); __block BOOL stop; // =============== 1A =============== MyBlock primitiveBlock = ^{ NSLog(@"Ran primitive implementation via assignment. (stop: %@ / %p)", @(stop), &stop); // stop only "captured" when referencing within a locally assigned block, if this line is commented out, stop isn't updated }; // =============== 1A =============== [self primitive_cancellable_dispatch_after:delay block:^{ NSLog(@"Ran primitive implementation via inline. (stop: %@ / %p)", @(stop), &stop); } stop:&stop]; __block Task *task = [self reference_cancellable_dispatch_after:delay block:^{ NSLog(@"Ran reference implementation: (task.shouldCancel: %@)",@(task.shouldCancel)); }]; task.shouldCancel = NO; // works as expected stop = NO; // stop isn't updated as expected, when checking value within "primitive_cancellable_dispatch_after", always returns no } - (void)primitive_cancellable_dispatch_after:(dispatch_time_t)delay block:(MyBlock)block stop:(BOOL*)stop { dispatch_after(delay, dispatch_get_main_queue(), ^{ BOOL shouldStop = *stop; // stop doesn't seem to resolving correctly, stop is always "NO", unless assigning a local block outside NSLog(@"Checking primitive stop (shouldStop: %@ / %p)", @(shouldStop), stop); if(!shouldStop && block) { block(); NSLog(@"Checking primitive stop (shouldStop: %@ / %p)", @(shouldStop), stop); } }); } /*@interface Task : NSObject @property (nonatomic, assign) BOOL shouldCancel; @property (nonatomic, strong) Task *task; @end @implementation Task @end*/ - (Task*)reference_cancellable_dispatch_after:(dispatch_time_t)delay block:(MyBlock)block { Task *task = [Task new]; dispatch_after(delay, dispatch_get_main_queue(), ^{ if(!task.shouldCancel && block) { block(); } }); return task; }
Replies
9
Boosts
0
Views
2.2k
Activity
Jun ’21
Load dylibs signed by different team
Hello again. We have a sandboxed app in macOS App Store. It has to load dylib files using dlopen(). The dylib files are signed by our vendor. When the app tries to load them, we see this error similar to "mapping process and mapped file have different Team IDs". We tried adding disable-library-validation but when we do so, the app refuses even to start. Is there a way to achieve loading of dylibs signed by another team? Also, this issue happens with only a few users. I don't see this issue on my development machines.
Replies
4
Boosts
0
Views
2.9k
Activity
Jun ’21