I have a viewcontroller functioning as QRCode scanner, and the below is the part about the scan-output. It works well on iOS 12/13, but only crashed on iOS 14.
AVMetadataMachineReadableCodeObject *metadataObj = [metadataObjects objectAtIndex:0];
if ([[metadataObj type] isEqualToString:AVMetadataObjectTypeQRCode]) {
NSString *codeString=[metadataObj stringValue];
[self performSelectorOnMainThread:#selector(stopReading) withObject:nil waitUntilDone:NO];
UIAlertController * alert = [UIAlertController
alertControllerWithTitle:#"QRCode is Scanned"
message:#""
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* ok = [UIAlertAction
actionWithTitle:#"OK"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
// [self startReading];
// [_viewPreview bringSubviewToFront:_previewFrame];
NSLog(#"The Scanned QRCode as %#",codeString);
[self.delegate addItemViewController:self didFinishEnteringItem:codeString];
[self.navigationController popViewControllerAnimated:YES];
}];
[alert addAction:ok];
[self presentViewController:alert animated:YES completion:nil];
and then the crash log came out as below, and this was ocurred on the code as "UIAlertController * alert", I think there might be something wrong for iOS 14.
2021-04-15 16:21:04.194 ntpc[5257:1741639] This application is modifying the autolayout engine from a background thread after the engine was accessed from the main thread. This can lead to engine corruption and weird crashes.
Stack:(
0 CoreAutoLayout 0x00000001c1b80548 011F5CA5-D31B-3CDC-83C2-C7CB66064075 + 62792
1 CoreAutoLayout 0x00000001c1b80904 011F5CA5-D31B-3CDC-83C2-C7CB66064075 + 63748
2 UIKitCore 0x00000001b0204ef0 CC6E5AC7-8248-35F6-8B42-2E25C93DCF0A + 16047856
3 UIKitCore 0x00000001b0206294 CC6E5AC7-8248-35F6-8B42-2E25C93DCF0A + 16052884
4 UIKitCore 0x00000001af33d0a0 CC6E5AC7-8248-35F6-8B42-2E25C93DCF0A + 549024
5 UIKitCore 0x00000001af338880 CC6E5AC7-8248-35F6-8B42-2E25C93DCF0A + 530560
6 UIKitCore 0x00000001af338aec CC6E5AC7-8248-35F6-8B42-2E25C93DCF0A + 531180
7 UIKitCore 0x00000001af338f7c CC6E5AC7-8248-35F6-8B42-2E25C93DCF0A + 532348
8 UIKitCore 0x00000001af33d92c CC6E5AC7-8248-35F6-8B42-2E25C93DCF0A + 551212
9 UIKitCore 0x00000001af33d778 CC6E5AC7-8248-35F6-8B42-2E25C93DCF0A + 550776
10 UIKitCore 0x00000001af318c94 CC6E5AC7-8248-35F6-8B42-2E25C93DCF0A + 400532
11 UIKitCore 0x00000001af724114 CC6E5AC7-8248-35F6-8B42-2E25C93DCF0A + 4641044
12 UIKitCore 0x00000001af7247e8 CC6E5AC7-8248-35F6-8B42-2E25C93DCF0A + 4642792
13 UIKitCore 0x00000001af73a820 CC6E5AC7-8248-35F6-8B42-2E25C93DCF0A + 4732960
14 UIKitCore 0x00000001af732e18 CC6E5AC7-8248-35F6-8B42-2E25C93DCF0A + 4701720
15 UIKitCore 0x00000001af7363ac CC6E5AC7-8248-35F6-8B42-2E25C93DCF0A + 4715436
16 UIKitCore 0x00000001af737240 CC6E5AC7-8248-35F6-8B42-2E25C93DCF0A + 4719168
17 UIKitCore 0x00000001af737550 CC6E5AC7-8248-35F6-8B42-2E25C93DCF0A + 4719952
18 UIKitCore 0x00000001af737190 CC6E5AC7-8248-35F6-8B42-2E25C93DCF0A + 4718992
19 UIKitCore 0x00000001af737614 CC6E5AC7-8248-35F6-8B42-2E25C93DCF0A + 4720148
20 ntpc 0x00000001030dce88 ntpc + 1429128
21 AVFCapture 0x00000001c6794b38 083B23EB-2DC8-3813-817B-6F1A40C9EC24 + 498488
22 AVFCapture 0x00000001c6793c60 083B23EB-2DC8-3813-817B-6F1A40C9EC24 + 494688
23 CMCapture 0x00000001c67ff5e4 BD2C0FD0-B1F9-374F-9D59-2B5266446EFF + 153060
24 CMCapture 0x00000001c6a61304 BD2C0FD0-B1F9-374F-9D59-2B5266446EFF + 2650884
25 libdispatch.dylib 0x00000001ad1b3280 AF27E74C-BE4A-3364-BB27-AED9916CE02D + 397952
26 libdispatch.dylib 0x00000001ad158390 AF27E74C-BE4A-3364-BB27-AED9916CE02D + 25488
27 libdispatch.dylib 0x00000001ad1690ac AF27E74C-BE4A-3364-BB27-AED9916CE02D + 94380
28 libdispatch.dylib 0x00000001ad15bc94 AF27E74C-BE4A-3364-BB27-AED9916CE02D + 40084
29 libdispatch.dylib 0x00000001ad15c8a8 AF27E74C-BE4A-3364-BB27-AED9916CE02D + 43176
30 libdispatch.dylib 0x00000001ad166338 AF27E74C-BE4A-3364-BB27-AED9916CE02D + 82744
31 libsystem_pthread.dylib 0x00000001f5d9d5a4 _pthread_wqthread + 272
32 libsystem_pthread.dylib 0x00000001f5da0874 start_wqthread + 8
)
2021-04-15 16:21:04.195 ntpc[5257:1741639] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Modifications to the layout engine must not be performed from a background thread after it has been accessed from the main thread.'
*** First throw call stack:
(0x1ad57a9d8 0x1c18fdb54 0x1c1b80640 0x1c1b80904 0x1b0204ef0 0x1b0206294 0x1af33d0a0 0x1af338880 0x1af338aec 0x1af338f7c 0x1af33d92c 0x1af33d778 0x1af318c94 0x1af724114 0x1af7247e8 0x1af73a820 0x1af732e18 0x1af7363ac 0x1af737240 0x1af737550 0x1af737190 0x1af737614 0x1030dce88 0x1c6794b38 0x1c6793c60 0x1c67ff5e4 0x1c6a61304 0x1ad1b3280 0x1ad158390 0x1ad1690ac 0x1ad15bc94 0x1ad15c8a8 0x1ad166338 0x1f5d9d5a4 0x1f5da0874)
libc++abi.dylib: terminating with uncaught exception of type NSException
Please help....
As the error message says you try to modify the layout on a background thread:
This application is modifying the autolayout engine from a background thread
You have to present the alert controller on the main thread:
dispatch_async(dispatch_get_main_queue(), ^{
[self presentViewController:alert animated:YES completion:nil]
});
All interactions with the UI must be done in the Main Thread so you need to wrap it in a dispatch in the main thread, i.e:
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertController * alert = [UIAlertController alertControllerWithTitle:#"QRCode is Scanned" message:#"" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* ok = [UIAlertAction actionWithTitle:#"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
[self.delegate addItemViewController:self didFinishEnteringItem:codeString];
[self.navigationController popViewControllerAnimated:YES];
}];
[alert addAction:ok];
[self presentViewController:alert animated:YES completion:nil];
});
On the other hand, this crash is not real. It is caused by the Main Thread checker that Xcode has enabled by default. I recommend you to keep it enabled.
You can find more information in this link Main Thread Checker
from the log reason: 'Modifications to the layout engine must not be performed from a background thread after it has been accessed from the main thread.'
You can print whether it's in the main thread. If not, You can change the code to main thread. because only the main thread can change and layout the UIView.
Related
I am getting the following crash in HockeyApp more seriously in iOS10. Please find the crash log as given below.
Thread 4 Crashed:
0 libobjc.A.dylib 0x0000000187242f30 objc_msgSend + 16
1 UIKit 0x000000018e86e914 -[UIWebDocumentView _updateSubviewCaches] + 36
2 UIKit 0x000000018e69093c -[UIWebDocumentView subviews] + 88
3 UIKit 0x000000018e941bd4 -[UIView(CALayerDelegate) _wantsReapplicationOfAutoLayoutWithLayoutDirtyOnEntry:] + 68
4 UIKit 0x000000018e63d770 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1248
5 QuartzCore 0x000000018bb0640c -[CALayer layoutSublayers] + 144
6 QuartzCore 0x000000018bafb0e8 CA::Layer::layout_if_needed(CA::Transaction*) + 288
7 QuartzCore 0x000000018bafafa8 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 28
8 QuartzCore 0x000000018ba77c64 CA::Context::commit_transaction(CA::Transaction*) + 248
9 QuartzCore 0x000000018ba9f0d0 CA::Transaction::commit() + 508
10 QuartzCore 0x000000018ba9faf0 CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 116
11 CoreFoundation 0x00000001887a57dc __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 28
12 CoreFoundation 0x00000001887a340c __CFRunLoopDoObservers + 368
13 CoreFoundation 0x00000001886d2068 CFRunLoopRunSpecific + 472
14 WebCore 0x000000018d273a2c RunWebThread(void*) + 452
15 libsystem_pthread.dylib 0x000000018788b860 _pthread_body + 236
16 libsystem_pthread.dylib 0x000000018788b770 _pthread_start + 280
17 libsystem_pthread.dylib 0x0000000187888dbc thread_start + 0
Any idea what is going on here ?
Seems like the following crash groups are also related.
Crash Group 1
[UIWebBrowserView _collectAdditionalSubviews]
objc_msgSend() selector name: autorelease
Crash Group 2
[UIWebDocumentView subviews]
objc_msgSend() selector name: arrayByAddingObjectsFromArray:
I am answering to my own question, since I am able to replicate this issue and found the root cause.
Please note the following.
1. I am using a UIWebView. First of all, this is not recommended.
2. The following way of implementation causes this issue. I am writing pseudo-code here to demonstrate the problem.
#implementation MyViewController
- (void)loadView {
//creating UIWebView Here
self.webView = [[UIWebView alloc] initWithFrame:_some_frame];
//setting the web view properties here.
//Adding to the view
[self.view addSubView: self.webView];
[self populateWebView];
}
- (void) populateWebView {
[self.webView loadHTMLString:_some_html
baseURL:[NSURL fileURLWithPath:_some_path]];
}
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
if (self.webView) {
//The following two lines causing this issue.
self.webView.scrollView.contentInset = _some_insets;
self.webView.scrollView.scrollIndicatorInsets = _some_insets;
}
}
#end
3. The solution is given below.
#implementation MyViewController
- (void)loadView {
//creating UIWebView Here
self.webView = [[UIWebView alloc] initWithFrame:_some_frame];
//setting the web view properties here.
//Adding to the view
[self.view addSubView: self.webView];
[self populateWebView];
}
- (void) populateWebView {
[self.webView loadHTMLString:_some_html
baseURL:[NSURL fileURLWithPath:_some_path]];
}
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
webView.scrollView.contentInset = _some_insets;
webView.scrollView.scrollIndicatorInsets = _some_insets;
}
#end
In my actual code, I was using a custom WebView class here by subclassing the UIWebView. Not think that will create some issue. The root cause is setting the "contentInset" and "scrollIndicatorInsets" in viewDidLayoutSubviews which is not a good idea. When I put the break points, "viewDidLayoutSubviews" called several times and eventually App crashes.
As a solution I moved the following part of the code into "webViewDidFinishLoad" which will call only when the WebView is ready after finished loading. So it makes sense to add this code under this delegate method.
webView.scrollView.contentInset = _some_insets;
webView.scrollView.scrollIndicatorInsets = _some_insets;
UPDATE 2
My app is crashing when presenting it modally after a user taps a button in ViewController1. In my storyboard, I have a standard present modally segue set to pop up the UINavController/UITableViewController containing the UISearchBar. That's failing every time.
However, in my AppDelegate, if I set the window's rootViewController to the same UINavController/UITableViewController, everything works as expected.
For some reason transitioning via segue and then acting the UISearchBar is causing the crash.
UPDATE 1
I'm now receiving the following error when tapping one letter:
2015-02-03 12:23:35.262 Afar D[28348:2740681] -[NSNull length]: unrecognized selector sent to instance 0x10e352ce0
2015-02-03 12:23:40.313 Afar D[28348:2740681] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull length]: unrecognized selector sent to instance 0x10e352ce0'
*** First throw call stack:
(
0 CoreFoundation 0x000000010e0a9f35 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010dd42bb7 objc_exception_throw + 45
2 CoreFoundation 0x000000010e0b104d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x000000010e00927c ___forwarding___ + 988
4 CoreFoundation 0x000000010e008e18 _CF_forwarding_prep_0 + 120
5 CoreFoundation 0x000000010df89a7b CFStringCompareWithOptionsAndLocale + 219
6 Foundation 0x000000010d6822b7 -[NSString compare:options:range:] + 29
7 UIKit 0x000000010c5f53b4 -[UIPhysicalKeyboardEvent _matchesKeyCommand:] + 224
8 UIKit 0x000000010c53c12e -[UIResponder(Internal) _keyCommandForEvent:] + 285
9 UIKit 0x000000010c53c197 -[UIResponder(Internal) _keyCommandForEvent:] + 390
10 UIKit 0x000000010c53c197 -[UIResponder(Internal) _keyCommandForEvent:] + 390
11 UIKit 0x000000010c53c197 -[UIResponder(Internal) _keyCommandForEvent:] + 390
12 UIKit 0x000000010c53c197 -[UIResponder(Internal) _keyCommandForEvent:] + 390
13 UIKit 0x000000010c53c197 -[UIResponder(Internal) _keyCommandForEvent:] + 390
14 UIKit 0x000000010c53c197 -[UIResponder(Internal) _keyCommandForEvent:] + 390
15 UIKit 0x000000010c53c197 -[UIResponder(Internal) _keyCommandForEvent:] + 390
16 UIKit 0x000000010c3d8f0a -[UIApplication _handleKeyUIEvent:] + 126
17 UIKit 0x000000010c5c7fcc -[UIKeyboardImpl _handleKeyEvent:executionContext:] + 66
18 UIKit 0x000000010c75bbb7 -[UIKeyboardLayoutStar completeRetestForTouchUp:timestamp:interval:executionContext:] + 3611
19 UIKit 0x000000010c75a8e5 -[UIKeyboardLayoutStar touchUp:executionContext:] + 1374
20 UIKit 0x000000010c5d531b __28-[UIKeyboardLayout touchUp:]_block_invoke + 242
21 UIKit 0x000000010cb23914 -[UIKeyboardTaskQueue continueExecutionOnMainThread] + 332
22 UIKit 0x000000010c5d521c -[UIKeyboardLayout touchUp:] + 252
23 UIKit 0x000000010c5d5cc6 -[UIKeyboardLayout touchesEnded:withEvent:] + 319
24 UIKit 0x000000010c40b308 -[UIWindow _sendTouchesForEvent:] + 735
25 UIKit 0x000000010c40bc33 -[UIWindow sendEvent:] + 683
26 UIKit 0x000000010c3d89b1 -[UIApplication sendEvent:] + 246
27 UIKit 0x000000010c3e5a7d _UIApplicationHandleEventFromQueueEvent + 17370
28 UIKit 0x000000010c3c1103 _UIApplicationHandleEventQueue + 1961
29 CoreFoundation 0x000000010dfdf551 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
30 CoreFoundation 0x000000010dfd541d __CFRunLoopDoSources0 + 269
31 CoreFoundation 0x000000010dfd4a54 __CFRunLoopRun + 868
32 CoreFoundation 0x000000010dfd4486 CFRunLoopRunSpecific + 470
33 GraphicsServices 0x000000010fc109f0 GSEventRunModal + 161
34 UIKit 0x000000010c3c4420 UIApplicationMain + 1282
35 My App 0x000000010a5e1c63 main + 115
36 libdyld.dylib 0x000000010e75a145 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
I'm using iOS8's new UISearchController to manage a UISearchBar for filtering data in a table. If I activate the UISearchBar, the app crashes as soon as I type the first letter (Interestingly, the on-screen keyboard doesn't appear in the Simulator, but I don't think that's related).
In order to narrow things down, I've commented almost everything out of my UIViewController so that the UITableView renders nothing. I've implemented UISearchControllerDelegate and UISearchBarDelegate just so I can log when each method gets called. However, after typing the first letter, I receive no console messages. I don't even know where I could set a breakpoint.
Here's the crash I get:
-[NSNull length]: unrecognized selector sent to instance 0x107602ce0
Note that nowhere in my file am I calling length on anything. Something behind the scenes is, but I can't figure out what.
Here's my code to set up the UISearchController:
- (void)viewDidLoad
{
[super viewDidLoad];
self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
self.searchController.searchResultsUpdater = self;
self.searchController.definesPresentationContext = true;
self.searchController.hidesNavigationBarDuringPresentation = false;
[self.searchController.searchBar sizeToFit];
self.tableView.tableHeaderView = self.searchController.searchBar;
self.searchController.searchBar.delegate = self;
self.searchController.delegate = self;
}
By request, here are my delegate methods (implemented just to see if anything gets called after typing the first letter - they don't):
#pragma mark - UISearchResultsUpdating
- (void)updateSearchResultsForSearchController:(UISearchController *)searchController
{
NSLog(#"%s", __PRETTY_FUNCTION__);
}
#pragma mark - UISearchControllerDelegate
- (void)didDismissSearchController:(UISearchController *)searchController
{
NSLog(#"%s", __PRETTY_FUNCTION__);
}
- (void)didPresentSearchController:(UISearchController *)searchController
{
NSLog(#"%s", __PRETTY_FUNCTION__);
}
- (void)presentSearchController:(UISearchController *)searchController
{
NSLog(#"%s", __PRETTY_FUNCTION__);
}
- (void)willDismissSearchController:(UISearchController *)searchController
{
NSLog(#"%s", __PRETTY_FUNCTION__);
}
- (void)willPresentSearchController:(UISearchController *)searchController
{
NSLog(#"%s", __PRETTY_FUNCTION__);
}
#pragma mark - UISearchBarDelegate
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
NSLog(#"%s", __PRETTY_FUNCTION__);
}
- (BOOL)searchBar:(UISearchBar *)searchBar shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
NSLog(#"%s", __PRETTY_FUNCTION__);
return true;
}
- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
{
NSLog(#"%s", __PRETTY_FUNCTION__);
return true;
}
- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar
{
NSLog(#"%s", __PRETTY_FUNCTION__);
}
- (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar
{
NSLog(#"%s", __PRETTY_FUNCTION__);
return true;
}
- (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar
{
NSLog(#"%s", __PRETTY_FUNCTION__);
}
NSNull is just a singleton object used to represent null. It is traditionally used to wrap around nil values in containers(arrays and dictionaries) that cannot handle nil entries.
This error often comes up when parsing json and trying to add the result in a collection.
Are you doing something like this in your delegate method(s)?
Edit: Judging by the message you are sending to that NSNull (length), you probably get an "empty" result for a string you asked for and expected not be nil.
After burning an entire day struggling with this, it came down to a totally unrelated problem: a corrupted storyboard.
This SO question recommended finding which scene was corrupt and recreating it. Unfortunately there was no way for me to determine that, so after some trial and error, it ended up being the initial view controller in my storyboard, which happened to be a UINavigationController. I deleted that, added it back in, and everything is golden.
I get this crash on iOS 7,
Assertion failed: (result == KERN_SUCCESS), function + [XPCMachSendRight wrapSendRight:], file /SourceCache/XPCObjects/XPCObjects-46/XPCMachSendRight.m, line27.
Steps which lead to this crash are,
Opening MFMailComposeViewController
Press home button
App crashed.
Here is crash report,
Thread 0 Crashed:
0 libsystem_kernel.dylib 0x393bf1fc 0x393ac000 + 78332
1 libsystem_pthread.dylib 0x39426a4f 0x39423000 + 14927
2 libsystem_c.dylib 0x39370083 0x39326000 + 303235
3 libsystem_c.dylib 0x39370035 0x39326000 + 303157
4 libsystem_c.dylib 0x3934fc67 0x39326000 + 171111
5 XPCObjects 0x375a7905 0x375a2000 + 22789
6 UIKit 0x317b41f9 0x3128d000 + 5403129
7 UIKit 0x31529d45 0x3128d000 + 2739525
8 QuartzCore 0x30f54af9 0x30f13000 + 269049
9 QuartzCore 0x30f1b077 0x30f13000 + 32887
10 QuartzCore 0x30f1ae1b 0x30f13000 + 32283
11 UIKit 0x31318deb 0x3128d000 + 572907
12 UIKit 0x31318d53 0x3128d000 + 572755
13 CoreFoundation 0x2eaddf6f 0x2ea3e000 + 655215
14 CoreFoundation 0x2eadb8fb 0x2ea3e000 + 645371
15 CoreFoundation 0x2eadbbb5 0x2ea3e000 + 646069
16 CoreFoundation 0x2ea4653d 0x2ea3e000 + 34109
17 CoreFoundation 0x2ea4631f 0x2ea3e000 + 33567
18 GraphicsServices 0x337762e7 0x3376f000 + 29415
19 UIKit 0x312fd1e1 0x3128d000 + 459233
20 MYAPP 0x0002d5c9 main (main.mm:18)
21 MYAPP 0x0002d524 start + 36
I found similar problem mentioned here: app get crashed while navigating to RootViewController from Message popup
Crash occurs rarely. I don't know what [XPCMachSendRight wrapSendRight:] this is and how to prevent it from crashing my app?
Before using MFMailComposeViewController class, you must always check to see if the current device is configured to send email at all using the canSendMail method. If the user’s device is not set up for the delivery of email, you can notify the user or simply disable the email dispatch features in your application. You should not attempt to use this interface if the canSendMail method returns NO.
Use this code....
if ([MFMailComposeViewController canSendMail])
{
MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
mailer.mailComposeDelegate = self;
[mailer setSubject:#"A Message from Bloomingkids"];
NSArray *toRecipients = [NSArray arrayWithObjects:#"support#bloomingkids.com", nil];
[mailer setToRecipients:toRecipients];
UIImage *myImage = [UIImage imageNamed:#"bloomingKidsLogo.png"];
NSData *imageData = UIImagePNGRepresentation(myImage);
[mailer addAttachmentData:imageData mimeType:#"image/png" fileName:#"Images"];
NSString *emailBody = #"Have you seen the Bloomingkids web site?";
[mailer setMessageBody:emailBody isHTML:NO];
[self presentViewController:mailer animated:YES completion:nil];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Failure"
message:#"Your device doesn't support the composer sheet"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles: nil];
[alert show];
}
Add any email account in your device first means setup an email account...
We had compiled and deployed an app in iOS 6 environment. But, now the app is getting crash in iOS 7 whenever showing an alert.
App simply getting crash in [alertView show];
But, the same app is running perfect in iOS 6.
Code for showing alert
-(void)displayAlertWithMessage:(NSString *)message withTitle:(NSString *)title andTag:(int)tag
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:title message:message delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertView show];
}
and calling like this
[self displayAlertWithMessage:#"Please enter valid username!" withTitle:nil andTag:1];
Here, is the crash log.
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </Users/developer/Library/Application Support/iPhone Simulator/7.0/Applications/A0BCB945-8E4A-4D06-BEE8-240FF45ECF78/MyProject.app> (loaded)' with name '_UIModalItemAppViewController''
*** First throw call stack:
(
0 CoreFoundation 0x003176f4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x027c88b6 objc_exception_throw + 44
2 CoreFoundation 0x003174cb +[NSException raise:format:] + 139
3 UIKit 0x015d1bec -[UINib instantiateWithOwner:options:] + 951
4 UIKit 0x01444f05 -[UIViewController _loadViewFromNibNamed:bundle:] + 280
5 UIKit 0x014456ad -[UIViewController loadView] + 302
6 UIKit 0x014459ae -[UIViewController loadViewIfRequired] + 78
7 UIKit 0x01445eb4 -[UIViewController view] + 35
8 UIKit 0x018dc9da -[_UIModalItemsCoordinator _presentingViewControllerForAlertCompatibilityCreateIfNeeded:] + 248
9 UIKit 0x018dc8dd -[_UIModalItemsCoordinator _presentingViewControllerForAlertCompatibility] + 41
10 UIKit 0x01812801 -[UIAlertView(Private) popupAlertAnimated:animationType:atOffset:] + 382
11 UIKit 0x01812c1d -[UIAlertView(Private) popupAlertAnimated:animationType:] + 56
12 UIKit 0x01817c17 -[UIAlertView showWithAnimationType:] + 48
13 UIKit 0x01817c45 -[UIAlertView show] + 41
14 MyProject 0x000330a8 -[LoginViewController displayAlertWithMessage:withTitle:andTag:] + 232
15 MyProject 0x00032e8b -[LoginViewController isValidContent] + 299
16 MyProject 0x00033136 -[LoginViewController showSetPinView] + 54
17 libobjc.A.dylib 0x027da874 -[NSObject performSelector:withObject:withObject:] + 77
18 UIKit 0x0133524c -[UIApplication sendAction:to:from:forEvent:] + 108
19 UIKit 0x013351d8 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
20 UIKit 0x0142ba5d -[UIControl sendAction:to:forEvent:] + 66
21 UIKit 0x0142be20 -[UIControl _sendActionsForEvents:withEvent:] + 577
22 UIKit 0x0142b0cf -[UIControl touchesEnded:withEvent:] + 641
23 UIKit 0x0137221d -[UIWindow _sendTouchesForEvent:] + 852
24 UIKit 0x01372e84 -[UIWindow sendEvent:] + 1232
25 UIKit 0x01346b86 -[UIApplication sendEvent:] + 242
26 MyProject 0x000c2c75 -[Application sendEvent:] + 101
27 UIKit 0x0133135f _UIApplicationHandleEventQueue + 11421
28 CoreFoundation 0x002a096f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
29 CoreFoundation 0x002a02fb __CFRunLoopDoSources0 + 235
30 CoreFoundation 0x002bd3ce __CFRunLoopRun + 910
31 CoreFoundation 0x002bcbf3 CFRunLoopRunSpecific + 467
32 CoreFoundation 0x002bca0b CFRunLoopRunInMode + 123
33 GraphicsServices 0x036f0a27 GSEventRunModal + 192
34 GraphicsServices 0x036f084e GSEventRun + 104
35 UIKit 0x01333f0b UIApplicationMain + 1225
36 MyProject 0x00006612 main + 178
37 MyProject 0x00006555 start + 53
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Thanks in advance.
As per crash log it says to me "[UIViewController _loadViewFromNibNamed:bundle:]" unable to load nib file.
But, in my project I had created a category for UIViewController class and overridden the -(id)init method. Upto ios6, while showing an alert this category method is not at all executing, but from ios7 onwards overridden init() method of UIViewController.
So, I fixed this issue by adding the another validation in UIViewController category's init() method for checking the class method is UIAlertView or not, if it is UIAlertView then simply calling [super init]; instead of doing my other stuff relating to view controllers.
Sample code:
- (id)init
{
NSString *viewControllerName = [NSString stringWithFormat:#"%#",[self class]];
if([viewControllerName isEqualToString:#"UIAlertView"])
{
self = [super init];
}
else
{
// my stuff
}
return self;
}
you can test it.. try to avoid nil.. instead of that put something... like
[self displayAlertWithMessage:#"Please enter valid username!" withTitle:#"Hello" andTag:1]
and you need to release alert view so in function write release code...
I'm making this voice recording app, but for some reason it won't let me use this delete method without crashing:
-(void)deleteCurrentFiles {
if(recorder != nil) {
if([recorder isRecording]) {
[recorder stop];
}
[recorder release];
recorder = nil;
[self performSelector:#selector(resetTotalTimeLabel) withObject:nil afterDelay:1.0];
}
if(player != nil) {
if([player isPlaying]) {
[player stop];
}
[player release];
player = nil;
currentTime = 0;
timeSlider.value = 0;
[self performSelector:#selector(resetCurrentTimeLabel) withObject:nil afterDelay:0.1];
}
if(commentRecorder != nil) {
if([commentRecorder isRecording]) {
[commentRecorder stop];
}
}
}
The declarations of these instances:
AVAudioRecorder *recorder;
AVAudioRecorder *commentRecorder;
AVAudioPlayer *player;
In resetTotalTimeLabel and resetCurrentTimeLabel there is no referance to / usage of the recorders/player.
The error I get is:
-[__NSArrayI finishedRecording]: unrecognized selector sent to instance 0x1b3ba0
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI finishedRecording]: unrecognized selector sent to instance 0x1b3ba0'
*** Call stack at first throw:
(
0 CoreFoundation 0x35f08c7b __exceptionPreprocess + 114
1 libobjc.A.dylib 0x30186ee8 objc_exception_throw + 40
2 CoreFoundation 0x35f0a3e3 -[NSObject(NSObject) doesNotRecognizeSelector:] + 98
3 CoreFoundation 0x35eaf467 ___forwarding___ + 506
4 CoreFoundation 0x35eaf220 _CF_forwarding_prep_0 + 48
5 CoreFoundation 0x35ea3f79 -[NSObject(NSObject) performSelector:withObject:] + 24
6 Foundation 0x33fd3e6d __NSThreadPerformPerform + 272
7 CoreFoundation 0x35ebc8d1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 14
8 CoreFoundation 0x35e8cecd __CFRunLoopDoSources0 + 384
9 CoreFoundation 0x35e8c6f9 __CFRunLoopRun + 264
10 CoreFoundation 0x35e8c50b CFRunLoopRunSpecific + 226
11 CoreFoundation 0x35e8c419 CFRunLoopRunInMode + 60
12 GraphicsServices 0x35261d24 GSEventRunModal + 196
13 UIKit 0x3386557c -[UIApplication _run] + 588
14 UIKit 0x33862558 UIApplicationMain + 972
15 App Name 0x00002959 main + 80
16 App Name 0x00002904 start + 40
)
terminate called after throwing an instance of 'NSException'
It actually seems to happen to the recorder after this method is called.. So is there anything I should add to this method to make it work?
Any thoughts are greatly appriciated!
sending a message to an object which does not respond to it at a strange point in time is a good indication of a reference count imbalance. run your app with zombies enabled in Instruments. reproduce the crash and see if it is a zombie.