app crashed when popoverPresentationController and keyboard dismiss - ios

I have a UIViewController, which add a UITableView, a UISearchController. I present this ViewController as UIModalPresentationPopover style.If i only dismiss the ViewController, that's no problem.But when searching text and keyboard showed, then dismiss the ViewController, it crashed! It don't crash when i tap the area outside the popover view.
[Self dismissViewControllerAnimated:YES completion:nil];//dismiss
it'll crash when dismiss like this pic below.
enter image description here
enter image description here
Thread 1 > 19 UIApplicationMain
UIKit`UIApplicationMain:
0x11119d549 <+0>: pushq %rbp
0x11119d54a <+1>: movq %rsp, %rbp
0x11119d54d <+4>: pushq %r15
0x11119d54f <+6>: pushq %r14
0x11119d551 <+8>: pushq %r13
0x11119d553 <+10>: pushq %r12
0x11119d555 <+12>: pushq %rbx
0x11119d556 <+13>: pushq %rax
0x11119d557 <+14>: movq %rcx, %rbx
0x11119d55a <+17>: movq %rsi, -0x30(%rbp)
0x11119d55e <+21>: movl %edi, %r12d
0x11119d561 <+24>: movq 0x115d090(%rip), %r13 ; (void *)0x0000000114a1dc50: objc_retain
0x11119d568 <+31>: movq %rdx, %rdi
0x11119d56b <+34>: callq *%r13
0x11119d56e <+37>: movq %rax, %r14
0x11119d571 <+40>: movq %rbx, %rdi
0x11119d574 <+43>: callq *%r13
0x11119d577 <+46>: movq %rax, %r15
0x11119d57a <+49>: leaq 0x158700b(%rip), %r13 ; _UIApplicationLinkedOnVersion
0x11119d581 <+56>: movl (%r13), %eax
0x11119d585 <+60>: testl %eax, %eax
0x11119d587 <+62>: jne 0x11119d597 ; <+78>
0x11119d589 <+64>: cmpq $-0x1, 0x157fc7f(%rip) ; WebKitSetIsClassic + 7
0x11119d591 <+72>: jne 0x11119d60a ; <+193>
0x11119d593 <+74>: movl (%r13), %eax
0x11119d597 <+78>: cmpl $0x20100, %eax ; imm = 0x20100
0x11119d59c <+83>: jb 0x11119d5c2 ; <+121>
0x11119d59e <+85>: callq 0x11200f0a8 ; symbol stub for: objc_autoreleasePoolPush
0x11119d5a3 <+90>: movq %rax, %r13
0x11119d5a6 <+93>: movl %r12d, %edi
0x11119d5a9 <+96>: movq -0x30(%rbp), %rsi
0x11119d5ad <+100>: movq %r14, %rdx
0x11119d5b0 <+103>: movq %r15, %rcx
0x11119d5b3 <+106>: callq 0x11119d622 ; _UIApplicationMainPreparations
0x11119d5b8 <+111>: movq %r13, %rdi
0x11119d5bb <+114>: callq 0x11200f0a2 ; symbol stub for: objc_autoreleasePoolPop
0x11119d5c0 <+119>: jmp 0x11119d5d4 ; <+139>
0x11119d5c2 <+121>: movl %r12d, %edi
0x11119d5c5 <+124>: movq -0x30(%rbp), %rsi
0x11119d5c9 <+128>: movq %r14, %rdx
0x11119d5cc <+131>: movq %r15, %rcx
0x11119d5cf <+134>: callq 0x11119d622 ; _UIApplicationMainPreparations
0x11119d5d4 <+139>: movq 0x1586ef5(%rip), %rdi ; UIApp
0x11119d5db <+146>: movq 0x14d2b06(%rip), %rsi ; "_run"
0x11119d5e2 <+153>: callq *0x115d000(%rip) ; (void *)0x0000000114a20940: objc_msgSend
0x11119d5e8 <+159>: movq 0x115d001(%rip), %rbx ; (void *)0x0000000114a1dcc0: objc_release
0x11119d5ef <+166>: movq %r15, %rdi
0x11119d5f2 <+169>: callq *%rbx
0x11119d5f4 <+171>: movq %r14, %rdi
0x11119d5f7 <+174>: callq *%rbx
0x11119d5f9 <+176>: xorl %eax, %eax
0x11119d5fb <+178>: addq $0x8, %rsp
0x11119d5ff <+182>: popq %rbx
0x11119d600 <+183>: popq %r12
0x11119d602 <+185>: popq %r13
0x11119d604 <+187>: popq %r14
0x11119d606 <+189>: popq %r15
0x11119d608 <+191>: popq %rbp
0x11119d609 <+192>: retq
0x11119d60a <+193>: leaq 0x157fbff(%rip), %rdi ; _UIApplicationLinkedOnVersionOnce
0x11119d611 <+200>: leaq 0x1160910(%rip), %rsi ; __block_literal_global.1491
0x11119d618 <+207>: callq 0x11200edf6 ; symbol stub for: dispatch_once
0x11119d61d <+212>: jmp 0x11119d593 ; <+74>

First, cancel the searchController
[self searchBarCancelButtonClicked:yourSearchBar];
or
[self.searchDisplayController setActive:NO animated:YES];
and then dismiss the view controller.
[self dismissViewControllerAnimated:YES completion:nil];
This will help.

Try this
[self.view endEditing:YES];
[self dismissViewControllerAnimated:YES completion:nil];

Related

Method swizzle not working on iOS 10.1

I want to swizzle the method #property string in UIPasteboard:
+ (void) load {
....
[UIPasteboard jr_swizzleMethod:#selector(string) withMethod:#selector(stringSwizzle) error:nil];
[UIPasteboard jr_swizzleMethod:#selector(setString:) withMethod:#selector(setStringSwizzle:) error:nil];
....
}
When I called [[UIPasteboard generalPasteboard] setString:#"test"]; it enter my swizzle method. It works on iOS 7, iOS 8, and iOS 9. However, it failed on iOS 10.
The assembly is differnt of a test method:
- (void) pasteboradTest {
[aUIPasteboard setString:#"test"];
}
on iOS 9:
0xced0a <+0>: push {r7, lr}
0xced0c <+2>: mov r7, sp
0xced0e <+4>: sub sp, #0x8
0xced10 <+6>: movw r2, #0xa51c
0xced14 <+10>: movt r2, #0x0
0xced18 <+14>: add r2, pc
0xced1a <+16>: movw r3, #0xa2e2
0xced1e <+20>: movt r3, #0x0
0xced22 <+24>: add r3, pc
0xced24 <+26>: ldr r3, [r3]
0xced26 <+28>: movw r9, #0xbc8e
0xced2a <+32>: movt r9, #0x0
0xced2e <+36>: add r9, pc
0xced30 <+38>: movw r12, #0xc298
0xced34 <+42>: movt r12, #0x0
0xced38 <+46>: add r12, pc
0xced3a <+48>: str r0, [sp, #0x4]
0xced3c <+50>: str r1, [sp]
0xced3e <+52>: ldr.w r0, [r12]
0xced42 <+56>: ldr.w r1, [r9]
0xced46 <+60>: blx r3
0xced48 <+62>: add sp, #0x8
0xced4a <+64>: pop {r7, pc}
on iOS 10:
0x10008f78c <+0>: stp x29, x30, [sp, #-16]!
0x10008f790 <+4>: mov x29, sp
0x10008f794 <+8>: sub sp, sp, #16 ; =16
0x10008f798 <+12>: adrp x8, 9
0x10008f79c <+16>: add x8, x8, #592 ; =592
0x10008f7a0 <+20>: adrp x9, 11
0x10008f7a4 <+24>: add x9, x9, #3480 ; =3480
0x10008f7a8 <+28>: adrp x10, 12
0x10008f7ac <+32>: add x10, x10, #1776 ; =1776
0x10008f7b0 <+36>: str x0, [sp, #8]
0x10008f7b4 <+40>: str x1, [sp]
0x10008f7b8 <+44>: ldr x10, [x10]
0x10008f7bc <+48>: ldr x1, [x9]
0x10008f7c0 <+52>: mov x0, x10
0x10008f7c4 <+56>: mov x2, x8
0x10008f7c8 <+60>: bl 0x100094cb8 ; symbol stub for: objc_msgSend
0x10008f7cc <+64>: mov sp, x29
0x10008f7d0 <+68>: ldp x29, x30, [sp], #16
0x10008f7d4 <+72>: ret
UIPasteboard become a class cluster in iOS 10. The easiest way to notice that is to stop on breakpoint in your app and perform following command in lldb:
(lldb) po [UIPasteboard generalPasteboard]
<_UIConcretePasteboard: 0x6000000087a0>
That's the reason why swizzling doesn't work - you change implementation in UIPasteboard class, but your application invokes implementation of _UIConcretePasteboard private subclass.
You may try to workaround this issue with following code:
+ (void) load {
// ....
[[[UIPasteboard generalPasteboard] class] jr_swizzleMethod:#selector(string) withMethod:#selector(stringSwizzle) error:nil];
[[[UIPasteboard generalPasteboard] class] jr_swizzleMethod:#selector(setString:) withMethod:#selector(setStringSwizzle:) error:nil];
// ....
}
Of course, it's not the safe way to implement swizzling for class cluster - there is no any guarantee that you will not encounter any other private UIPasteboard subclass in runtime.

iOS app crashes after deleting Main.storyboard

I wanted to switch to xib so I deleted Main.storyboard. Now the app crashed with no output log in didFinishLaunchingWithOptions when [self.window makeKeyAndVisible] is called. I have already cleared Main Interface in Target - General - Deployment Info. Is the crash related to some links that should be removed when I deleted the Main.storyboard?
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
MainViewController *mvc = [[MainViewController alloc] init];
UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:mvc];
self.window.rootViewController = nvc;
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return [[AWSMobileClient sharedInstance] didFinishLaunching:application withOptions:launchOptions];
}
Breakpoint on 0x10759e180:
UIKit`-[UIWindow makeKeyAndVisible]:
0x10759e156 <+0>: pushq %rbp
0x10759e157 <+1>: movq %rsp, %rbp
0x10759e15a <+4>: pushq %rbx
0x10759e15b <+5>: pushq %rax
0x10759e15c <+6>: movq %rdi, %rbx
0x10759e15f <+9>: movq 0xc62182(%rip), %rsi ; "isHidden"
0x10759e166 <+16>: callq *0xce6074(%rip) ; (void *)0x0000000108f97800: objc_msgSend
0x10759e16c <+22>: testb %al, %al
0x10759e16e <+24>: je 0x10759e182 ; <+44>
0x10759e170 <+26>: movq 0xc63a11(%rip), %rsi ; "_orderFrontWithoutMakingKey"
0x10759e177 <+33>: movq %rbx, %rdi
0x10759e17a <+36>: callq *0xce6060(%rip) ; (void *)0x0000000108f97800: objc_msgSend
0x10759e180 <+42>: jmp 0x10759e194 ; <+62>
0x10759e182 <+44>: movq 0xc66a2f(%rip), %rsi ; "_updateLayerOrderingAndSetLayerHidden:"
0x10759e189 <+51>: xorl %edx, %edx
0x10759e18b <+53>: movq %rbx, %rdi
0x10759e18e <+56>: callq *0xce604c(%rip) ; (void *)0x0000000108f97800: objc_msgSend
0x10759e194 <+62>: cmpq %rbx, 0xce0045(%rip) ; _UIKeyWindow
0x10759e19b <+69>: je 0x10759e1b3 ; <+93>
0x10759e19d <+71>: movq 0xc66bfc(%rip), %rsi ; "makeKeyWindow"
0x10759e1a4 <+78>: movq %rbx, %rdi
0x10759e1a7 <+81>: addq $0x8, %rsp
0x10759e1ab <+85>: popq %rbx
0x10759e1ac <+86>: popq %rbp
0x10759e1ad <+87>: jmpq *0xce602d(%rip) ; (void *)0x0000000108f97800: objc_msgSend
0x10759e1b3 <+93>: addq $0x8, %rsp
0x10759e1b7 <+97>: popq %rbx
0x10759e1b8 <+98>: popq %rbp
0x10759e1b9 <+99>: retq
I finally found out that my newly added xib is missing a link from View to the the ViewController. In File's Owner - Connections Inspector - Outlets I dragged view outlet to the xib's view and then problem is solved.

Facing Issue with Share Extension from Sqlite database

I have an iOS App which has a sqlite DB and I am trying to implement Share extension. Hence, I have this DB shared by the main App as well as the share extension.
Following is my implementation
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
NSString *AppGroupId = #"XXXX";
NSURL *groupContainerURL = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:AppGroupId];
NSString *sharedDirectory = [groupContainerURL path];
sqliteDb = [sharedDirectory stringByAppendingPathComponent:#"MYDB.sqlite"];
success = [fileManager fileExistsAtPath:sqliteDb];
NSLog(#"path : %#", sqliteDb);
If I put my DB in NSDocument directory (without implementing share extension), everything works fine .
However, if I move it to shared directory and implement sharing extension, the app starts to crash when it goes in background.
Following are the logs and unfortunately I have not been able to debug why this is happening. Any help would be truly appreciated
The Crash log differ very time
like following
libsystem_kernel.dylib`mach_msg_trap:
0x31ae8504 <+0>: mov r12, sp
0x31ae8508 <+4>: push {r4, r5, r6, r8}
0x31ae850c <+8>: ldm r12, {r4, r5, r6}
0x31ae8510 <+12>: mvn r12, #30
0x31ae8514 <+16>: svc #0x80
-> 0x31ae8518 <+20>: pop {r4, r5, r6, r8}
0x31ae851c <+24>: bx lr
Foundation`-[NSConcreteMapTable dealloc]:
0x245b6f68 <+0>: push {r4, r5, r6, r7, lr}
0x245b6f6a <+2>: add r7, sp, #0xc
0x245b6f6c <+4>: push.w {r8, r10}
0x245b6f70 <+8>: sub sp, #0x8
0x245b6f72 <+10>: mov r4, r0
0x245b6f74 <+12>: movw r0, #0xa10
0x245b6f78 <+16>: movt r0, #0xd9f
0x245b6f7c <+20>: movw r1, #0xa0e
0x245b6f80 <+24>: add r0, pc
0x245b6f82 <+26>: movt r1, #0xd9f
0x245b6f86 <+30>: add r1, pc
0x245b6f88 <+32>: ldr.w r8, [r0]
0x245b6f8c <+36>: ldr r5, [r1]
0x245b6f8e <+38>: ldr.w r10, [r4, r8]
0x245b6f92 <+42>: adds r6, r4, r5
0x245b6f94 <+44>: mov r0, r6
0x245b6f96 <+46>: mov r1, r10
0x245b6f98 <+48>: bl 0x24644e10 ; empty
0x245b6f9c <+52>: ldr r0, [r4, r5]
0x245b6f9e <+54>: mov r1, r10
0x245b6fa0 <+56>: ldr r2, [r6, #0x30]
0x245b6fa2 <+58>: blx r2
0x245b6fa4 <+60>: movw r0, #0x9e4
0x245b6fa8 <+64>: mov.w r10, #0x0
0x245b6fac <+68>: movt r0, #0xd9f
0x245b6fb0 <+72>: str.w r10, [r4, r5]
0x245b6fb4 <+76>: add r0, pc
0x245b6fb6 <+78>: ldr.w r8, [r4, r8]
0x245b6fba <+82>: ldr r5, [r0]
0x245b6fbc <+84>: adds r6, r4, r5
0x245b6fbe <+86>: mov r1, r8
0x245b6fc0 <+88>: mov r0, r6
0x245b6fc2 <+90>: bl 0x24644e10 ; empty
-> 0x245b6fc6 <+94>: ldr r0, [r4, r5]
etc
NSString * const DataBaseName = #"MYDB.sqlite";
-(BOOL) createDataBase
{
BOOL success;
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:DataBaseName];
success = [fileManager fileExistsAtPath:writableDBPath];
if (success) return success;
NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:DataBaseName];
success = [fileManager copyItemAtPath:defaultDBPath toPath:writableDBPath error:&error];
if (!success) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error!!!" message:#"Failed to create writable database..." delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:nil];
[alert show];
}
return success;
}

Xcode 6 Swift WebThread crash with EXC_BAD_ACCESS error

I am using Xcode 6 with Swift to display PDF file through UIWebView in an iOS app as follow:
#IBOutlet weak var displayWebView: UIWebView!
func displayView(viewfile: NSData){
displayWebView.loadData(viewfile, MIMEType: "application/pdf", textEncodingName: "UTF-8", baseURL: nil)
}
The viewfile is a NSData comes from segue in a previous screen which is a tableview.
The display of PDF works normally. But when the app go back and forth to and from the previous screen, the app crashes in the 'loadData' step with "WebThread (xx): EXC_BAD_ACCESS (code=EXC_I386_GPFLT)" message as below:
libobjc.A.dylib`objc_msgSend:
0x106da3000 <+0>: testq %rdi, %rdi
0x106da3003 <+3>: jle 0x106da3068 ; <+104>
0x106da3005 <+5>: movq (%rdi), %r11
0x106da3008 <+8>: movq %rsi, %r10
-> 0x106da300b <+11>: andl 0x18(%r11), %r10d WebThread (24): EXC_BAD_ACCESS (code=EXC_I386_GPFLT)
0x106da300f <+15>: shlq $0x4, %r10
0x106da3013 <+19>: addq 0x10(%r11), %r10
0x106da3017 <+23>: cmpq (%r10), %rsi
Sometimes, the error is:
WebKitLegacy`-[WebDataSource(WebPrivate) dataSourceDelegate]:
0x10c51dbb0 <+0>: pushq %rbp
0x10c51dbb1 <+1>: movq %rsp, %rbp
0x10c51dbb4 <+4>: movq 0x11ad95(%rip), %rax ; WebDataSource._private
0x10c51dbbb <+11>: movq (%rdi,%rax), %rax
-> 0x10c51dbbf <+15>: movq 0x18(%rax), %rax WebThread (17): EXC_BAD_ACCESS (code=EXC_I386_GPFLT)
0x10c51dbc3 <+19>: popq %rbp
0x10c51dbc4 <+20>: retq
0x10c51dbc5 <+21>: nopw %cs:(%rax,%rax)
These crashes happen no matter target at iOS 8 and iOS 7 and the place of breakdown looks random. Although there are similar posts on similar symptoms, they are Objective-C solution instead of Swift.
Would someone inform the solution of problem in Swift?
why don't you update the view after calling "loadData"? the execution within the block is still synchronous relative to its thread.
[query findObjectsInBackgroundWithBlock:^(NSArray * _Nullable objects, NSError * _Nullable error) {
if (error) {
//handle error
}
else {
dispatch_async(dispatch_get_main_queue(), ^{
[self loadData];
[self updateView];
});
}
}];

IOS/Xcode: NSEntityDescription nil error

Hi based on a tutorial I have wired following method to Done button in Add New view controller.
The text field saves back to its own controller. The program builds and runs. But when you click the Done button to save the new record, it throws an error. The method seems to get the text entered--based on the presence of name NSString * #"jkl" 0x00007f9828d8d6b0 in the debugger but the NS entity is nil and it crashes.entity NSEntityDescription * nil 0x0000000000000000 I've triple checked the name of the entity and it is correct.
Can anyone tell me what might be going wrong? Thanks!
- (IBAction)save:(id)sender {
// Helpers
NSString *name = self.textField.text;
[[[UIAlertView alloc] initWithTitle:#"We got data" message:name delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil] show];
if (name && name.length) {
// Create Entity FOLLOWING LINE IS HIGHLIGHTED AND THROWS ERROR
NSEntityDescription *entity = [NSEntityDescription entityForName:#"TSPItem" inManagedObjectContext:self.managedObjectContext];
//END HIGHLIGHTED ERRROR
// Initialize Record
NSManagedObject *record = [[NSManagedObject alloc] initWithEntity:entity insertIntoManagedObjectContext:self.managedObjectContext];
// Populate Record
[record setValue:name forKey:#"name"];
[record setValue:[NSDate date] forKey:#"createdAt"];
// Save Record
NSError *error = nil;
if ([self.managedObjectContext save:&error]) {
// Dismiss View Controller
[self dismissViewControllerAnimated:YES completion:nil];
} else {
if (error) {
NSLog(#"Unable to save record.");
NSLog(#"%#, %#", error, error.localizedDescription);
}
// Show Alert View
[[[UIAlertView alloc] initWithTitle:#"Warning" message:#"Your field could not be saved." delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil] show];
}
} else {
// Show Alert View
[[[UIAlertView alloc] initWithTitle:#"Warning" message:#"Your field needs a name." delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil] show];
}
Edit:
Here is some additional stuff from one of the threads. I am not skilled enough at debugging to know what it means:
0x10ce9de77: leaq 0x26fa82(%rip), %r8 ; #"+entityForName: nil is not a legal NSManagedObjectContext parameter searching for entity name '%#'"
0x10ce9de7e: jmp 0x10ce9dece ; +[NSEntityDescription entityForName:inManagedObjectContext:] + 206
0x10ce9de80: movq 0x2c5311(%rip), %r14 ; (void *)0x000000010dce1458: NSException
0x10ce9de87: movq 0x2691ca(%rip), %rax ; (void *)0x000000010dca9a20: NSInvalidArgumentException
0x10ce9de8e: movq (%rax), %r15
0x10ce9de91: movq 0x2c52b8(%rip), %rcx ; (void *)0x000000010d585e90: NSString
0x10ce9de98: movq 0x2be8e9(%rip), %rdx ; "stringWithFormat:"
0x10ce9de9f: leaq 0x26fa7a(%rip), %r8 ; #"+entityForName: nil is not a legal NSPersistentStoreCoordinator for searching for entity name '%#'"
0x10ce9dea6: jmp 0x10ce9dece ; +[NSEntityDescription entityForName:inManagedObjectContext:] + 206
0x10ce9dea8: movq 0x2c52e9(%rip), %r14 ; (void *)0x000000010dce1458: NSException
0x10ce9deaf: movq 0x26919a(%rip), %rax ; (void *)0x000000010dca9a28: NSInternalInconsistencyException
0x10ce9deb6: movq (%rax), %r15
0x10ce9deb9: movq 0x2c5290(%rip), %rcx ; (void *)0x000000010d585e90: NSString
0x10ce9dec0: movq 0x2be8c1(%rip), %rdx ; "stringWithFormat:"
0x10ce9dec7: leaq 0x26fa72(%rip), %r8 ; #"+entityForName: could not locate an NSManagedObjectModel for entity name '%#'"
0x10ce9dece: movq 0x2692eb(%rip), %r12 ; (void *)0x000000010d6e9000: objc_msgSend
0x10ce9ded5: xorl %eax, %eax
0x10ce9ded7: movq %rcx, %rdi
0x10ce9deda: movq %rdx, %rsi
0x10ce9dedd: movq %r8, %rdx
0x10ce9dee0: movq %rbx, %rcx
0x10ce9dee3: callq *%r12
0x10ce9dee6: movq 0x2be55b(%rip), %rcx ; "exceptionWithName:reason:userInfo:"

Resources