Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Duplicate states in queue' - ios

I'm working on a project that use UISlideViewController. I know that this may be a duplicate question but non of the posts before about this topic helped me. I have a specific problem, as I managed to understand. My app crashes on this block. I have read before, it's important to put all work with the UI in the main thread. This is the code:
pageViewController.setViewControllers([viewController],
direction: direction,
animated: animated,
completion: { completed in
dispatch_async(dispatch_get_main_queue()) {
...
The error that I get is next:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Duplicate states in queue'
*** First throw call stack:
(0x183fd1900 0x18363ff80 0x183fd17d0 0x18494499c 0x1894dc9f4 0x1894dcdec...)
Testing it further I also get this error on the same line of code:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'No view controller managing visible view <UITableView: 0x12744aa00;
frame = (0 0; 375 515);
clipsToBounds = YES; autoresize = W+H;
gestureRecognizers = <NSArray: 0x12836cf60>;
layer = <CALayer: 0x1286226b0>;
contentOffset: {0, 0}; contentSize: {375, 291}>'
The bug is very hard to reproduce. One literally needs to touch and scroll multiple times on UIPageViewController to get this crash.
Thanks for your time and help.

You should put the setViewControllers:direction:animated:completion: code inside of a dispatch_async block. It worked for me.
https://stackoverflow.com/a/24749239

Related

NSInternalInconsistencyException - Animator is already stopped

Currently getting the following runtime exception
libc++abi: terminating with uncaught exception of type NSException
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Animator <UIViewPropertyAnimator(0x600003f24200) [stopped] interruptible> is already stopped!'
Because of the following line of code
// other code up here that modifies offsetAnimator
...
// stop any current running animations on offset
if let offsetAnimator = offsetAnimator {
offsetAnimator.stopAnimation(false) // this line is where the exception gets raised
offsetAnimator.finishAnimation(at: .end)
}
What is perplexing, however, is why this error is NOT readily reproducible
// doing this doesn't always result in an error
if let offsetAnimator = offsetAnimator {
offsetAnimator.stopAnimation(false)
offsetAnimator.finishAnimation(at: .end)
offsetAnimator.stopAnimation(false)
offsetAnimator.finishAnimation(at: .end)
}
What on earth is happening? Can someone explain to me why this error is occurring?
Why does it seem to only happen sporadically? Shouldn't calling .stop twice always trigger it?

Terminating app due to uncaught exception 'NSRangeException' when calling dequeueReusableCellWithReuseIdentifier:forIndexPath:

We've run into a crash and all we can see is these from the crashlog:
2018-11-02 10:15:01.744674-0400 Flights[385:17563] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndexedSubscript:]: index 0 beyond bounds for empty array'
*** First throw call stack:
(0x18555ed8c 0x1847185ec 0x1854f7750 0x1854e48ac 0x18f266b04 0x18f266084 0x18f265fd8 0x18f265eb8 0x18f2859dc 0x18f286c00 0x18f286a2c 0x100b1c304 0x100ea8b6c 0x100eaa24c 0x100eaa30c 0x100eaa680 0x185566580 0x185445748 0x18544a56c 0x10573e0c8 0x1855642d4 0x18544a41c 0x18f266f60 0x18f266084 0x18f265fd8 0x18f265eb8 0x18f265500 0x18f264730 0x18f133770 0x1896d525c 0x1896d93ec 0x189645aa0 0x18966d5d0 0x18966e450 0x185506910 0x185504238 0x185504884 0x185424da8 0x187407020 0x18f40578c 0x100b8c760 0x184eb5fc0)
libc++abi.dylib: terminating with uncaught exception of type NSException
We've enabled the all exceptions breakpoints and it points us to this line of code:
UICollectionViewCell* cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:path];
One thing that is very weird is that we can only reproduce this in iOS 11.3 devices. But all our other test devices work fine.
We are pretty much stuck. Anybody runs into this before and knows any workaround?
Not sure if it is a bug in iOS 11 or not, but the crash is cost by the following code of trying to dequeue a cell for sizing purposes in collectionView:collectionViewLayout:sizeForItemAt: and works fine on iOS 12 and above:
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let cell = self.collectionView(collectionView, cellForItemAt: indexPath)
let size = cell.systemLayoutSizeFitting(...)
return CGSize(width: collectionView.frame.width, height: size.height)
}
And we are loading the nib with bundle parameter being nil as the following.
let nib = UINib(nibName: "MyCell", bundle: nil)
collectionView.register(nib, forCellWithReuseIdentifier: "MyCell")
That for some reason gives us the obscure exception:
2018-11-02 10:15:01.744674-0400 Flights[385:17563] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndexedSubscript:]: index 0 beyond bounds for empty array'
*** First throw call stack:
(0x18555ed8c 0x1847185ec 0x1854f7750 0x1854e48ac 0x18f266b04 0x18f266084 0x18f265fd8 0x18f265eb8 0x18f2859dc 0x18f286c00 0x18f286a2c 0x100b1c304 0x100ea8b6c 0x100eaa24c 0x100eaa30c 0x100eaa680 0x185566580 0x185445748 0x18544a56c 0x10573e0c8 0x1855642d4 0x18544a41c 0x18f266f60 0x18f266084 0x18f265fd8 0x18f265eb8 0x18f265500 0x18f264730 0x18f133770 0x1896d525c 0x1896d93ec 0x189645aa0 0x18966d5d0 0x18966e450 0x185506910 0x185504238 0x185504884 0x185424da8 0x187407020 0x18f40578c 0x100b8c760 0x184eb5fc0)
libc++abi.dylib: terminating with uncaught exception of type NSException
However, changing the bundle parameter being .main (thanks to the comments) like the following give us a more appropriate crash log and call stack.
let nib = UINib(nibName: "MyCell", bundle: .main)
That leads us to the actual solution to the problem: do not call collectionView(collectionView, cellForItemAt: indexPath) during layout.

App crash when MFMessageComposeViewController is initialisation

I want to send a message through my app. I call the following method on click
#IBAction func sendMessage(_ sender: Any) {
if (MFMessageComposeViewController.canSendText()) {
let composeVC = MFMessageComposeViewController()
composeVC.messageComposeDelegate = self
// Configure the fields of the interface.
composeVC.recipients = ["4085551212"]
composeVC.body = "Hello from California!"
// Present the view controller modally.
self.presentViewController(composeVC, animated: true, completion: nil)
}
}
The problem is if I run the app on device, it crashes at MFMessageComposeViewController initialisation i.e.
let composeVC = MFMessageComposeViewController()
If I run the app in simulator, it crashes on presentation i.e.
self.present(composeVC, animated: true, completion: nil)
Error log when I run the app on device
2018-01-29 12:03:57.826816+0530 EWS[2495:806400] *** Assertion failure in -[UICGColor encodeWithCoder:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit/UIKit-3698.33.7/UIColor.m:1722
2018-01-29 12:03:57.827522+0530 EWS[2495:806400] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Only RGBA or White color spaces are supported in this situation.'
*** First throw call stack:
(0x183702364 0x182948528 0x183702238 0x18409d7f4 0x18d08fffc 0x1840574dc 0x18405e8d8 0x18d4ebf20 0x18d4eb74c 0x18d4e7044 0x1835d03c0 0x18d4e6d44 0x18d7f16fc 0x18d60bd18 0x18d60b94c 0x19aee4534 0x19aecbff4 0x19aecc314 0x1984ce830 0x101159ec0 0x101158888 0x1011584b4 0x1011589c0 0x18cc186b4 0x18cc18634 0x18cc031dc 0x18cc17f28 0x18cc17a48 0x18cc12f60 0x18cbe3f64 0x18d53931c 0x18d53b8a8 0x18d5347c0 0x1836aa97c 0x1836aa8fc 0x1836aa184 0x1836a7d5c 0x1835c7e58 0x185474f84 0x18cc4767c 0x101157170 0x1830e456c)
libc++abi.dylib: terminating with uncaught exception of type NSException
Error log when I run the app on simulator (without checking if(MFMessageComposeViewController.canSendText()))
2018-01-29 12:07:49.395714+0530 EWS[3533:67163] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present a nil modal view controller on target <EWS.BlockVC: 0x7f899c61db10>.'
*** First throw call stack:
Any help would be appreciated.
Okay,
When you run it in iPhone : The crash log clearly states that "Only RGBA or White color spaces are supported in this situation." So by hint I would say you are assigning color somewhere, (Some Global tint, navigation bar tint) , which doesn't apply to a MFMessageComposeViewController, hence its crashing.
When you run it in the simulator :
if (MFMessageComposeViewController.canSendText()), this line will prevent it from initialising the MFMessageComposeViewController, in the simulator as it cant send text, hence when you try to present it, its not yet initialised and crashing.
On a second thought, as per your code : self.presentViewController(composeVC, animated: true, completion: nil), this line should not even be called while running in the simulator as this line is inside the if statement, which wont get through.
Also change the tint color or any while initialising the controller, and tell me what the results are.

Customize camera overlay in applozic

I am using applozic chat sdk for ios and sending images , video successfully . My requirement is to change camera overlay. When I try to add overlay on camera it crashes.
let camaraObj : ALImagePickerController = ALImagePickerController()
let overlay =UIView(frame: UIScreen.mainScreen().bounds)
overlay.backgroundColor = UIColor.redColor()
camaraObj.cameraOverlayView = overlay
Crash log: libc++abi.dylib: terminating with uncaught exception of type NSException.
Any help ?
Looks like you are not setting the sourceType. ALImagePickerController is used for sending pictures from photos only. You need to explicitly set source type if you want to use it for camera.
i.e. self.mImagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
We just tried the same and got below exception:
2017-01-30 14:30:30.954540 applozicdemo[3106:1925853] Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Source type must be UIImagePickerControllerSourceTypeCamera' First throw call stack:
(0x1819de1c0 0x18041855c 0x187a945cc 0x187d23294 0x1003f9dcc 0x10016525c 0x10016521c 0x10016a284 0x18198bf2c 0x181989b18 0x1818b8048 0x18333e198 0x1878a42fc 0x18789f034 0x1000517b8 0x18089c5b8)
libc++abi.dylib: terminating with uncaught exception of type NSException

Unusual NSInternalInconsistencyException related to device orientation

I am getting an unusual error on an iPad app I am working on:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '+entityForName: could not locate an NSManagedObjectModel for entity name 'Card''
*** First throw call stack:
(0x35ef988f 0x31872259 0x37aee7e5 0x8aadd 0x30a35e33 0x30a42391 0x30a42201 0x30a420e7 0x30a41969 0x30a416ab 0x30a4156b 0x30a000bd 0x35e581fb 0x37349aa5 0x373496bd 0x373495c9 0x30b7ea73 0x30ae0b1f 0x30b7212b 0x30b720bb 0x30a40ba9 0x30bb8927 0x34c6e2e9 0x34c6de23 0x30bbeae9 0x34c47f09 0x35e587d3 0x35e59461 0x30c741af 0x30c7594d 0x30bab509 0x30a34893 0x30a2e8d7 0x309fcc6b 0x309fc70f 0x309fc0e3 0x35bcf22b 0x35ecd523 0x35ecd4c5 0x35ecc313 0x35e4f4a5 0x35e4f36d 0x30a2da13 0x30a2ae7d 0x83631 0x835f0)
This occurs only when I change my view controllers shouldAutorotateToInterfaceOrientation from:
return YES;
to:
if (interfaceOrientation==UIInterfaceOrientationLandscapeLeft || interfaceOrientation==UIInterfaceOrientationLandscapeRight)
return YES;
return NO;
Why would this cause an NSInternalInconsistencyException?
I did notice when debugging, that shouldAutorotateToInterfaceOrientation gets called about 20 times by the same function: [UIViewController _isSupportedInterfaceOrientation:]. This is not done recursively.
My app only has Landscape (left) and Landscape (right) in the supported orientations and Landscape (left) as the intial orientation
Thanks in advance.

Resources