Search code examples
iosobjective-cios6

openURL Issues on iOS


I'm currently experiencing some issues with the [[UIApplication sharedApplication] openURL:[NSURL URLWithString:]] method in Xcode:

In my iPhone app, I'm downloading a .txt file from a server and parsing it like this:

NSString * idHelper = [allLines objectAtIndex:18];
appId1 = [idHelper stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

"allLines" is an array with all the contents of the .txt file in it.

"appId1" is a NSString.

In the above code, I'm setting appId1 to this URL: http://itunes.apple.com/app/id343200656/

In my UIViewController's .xib I'm calling the following method with a UIButton:

- (IBAction)downloadApp:(id)sender { 

    NSLog(@"downloadApp1");

   [[UIApplication sharedApplication] openURL:[NSURL URLWithString:appId1]];
}

This method should open the mobile App Store and show the app from the link.

But everytime I call this method, the app crashes and I just can't figure out why.

Can anyone help me with this issue? Thank you very much!

Edit: Here is the crash log. Sorry.

`libsystem_c.dylib`memmove$VARIANT$Swift:
0x39df7006:  push   {r7, lr}
libsystem_c.dylib`memcpy$VARIANT$Swift + 2:
0x39df7008:  mov    r7, sp
0x39df700a:  subs   r3, r0, r1
0x39df700c:  beq.w  0x39df72ae           ; memcpy$VARIANT$Swift + 680
0x39df7010:  mov    r12, r0
0x39df7012:  cmp    r3, r2
0x39df7014:  blo.w  0x39df72b0                ; memcpy$VARIANT$Swift + 682
0x39df7018:  subs.w r3, r2, #32
0x39df701c:  bls.w  0x39df72a0                ; memcpy$VARIANT$Swift + 666
0x39df7020:  orr.w  lr, r0, r1
0x39df7024:  orr.w  lr, lr, r2
0x39df7028:  ands   lr, lr, #15
0x39df702c:  bne    0x39df7048                ; memcpy$VARIANT$Swift + 66
0x39df702e:  subs   r3, #32
0x39df7030:  vld1.8 {d0, d1, d2, d3}, [r1, :128]!
0x39df7034:  vst1.8 {d0, d1, d2, d3}, [r12, :128]!
0x39df7038:  bhi    0x39df702e                ; memcpy$VARIANT$Swift + 40
0x39df703a:  add    r1, r3
0x39df703c:  vld1.8 {d0, d1, d2, d3}, [r1, :128]
0x39df7040:  add    r12, r3
0x39df7042:  vst1.8 {d0, d1, d2, d3}, [r12, :128]
0x39df7046:  pop    {r7, pc}
0x39df7048:  tst.w  r12, #15
0x39df704c:  itttt  ne
0x39df704e:  ldrbne r3, [r1], #1
0x39df7052:  strbne r3, [r12], #1
0x39df7056:  subne  r2, #1
0x39df7058:  bne    0x39df7048                ; memcpy$VARIANT$Swift + 66
0x39df705a:  and    lr, r1, #15
0x39df705e:  bic    r1, r1, #15
0x39df7062:  subs.w r3, r2, #32`

The app crashes at "0x39df704e: ldrbne r3, [r1], #1" with a EXC_BAD_ACCESS (code=1, address= 0x0).

And here is the crash log with zombie objects enabled:

libobjc.A.dylib`objc_msgSend:
0x399955c0:  teq.w  r0, #0
0x399955c4:  beq    0x39995606                ; objc_msgSend + 70
0x399955c6:  push.w {r3, r4}
0x399955ca:  ldr    r4, [r0]
0x399955cc:  lsr.w  r9, r1, #2
0x399955d0:  ldr    r3, [r4, #8]
0x399955d2:  add.w  r3, r3, #8
0x399955d6:  ldr    r12, [r3, #-8]
0x399955da:  and.w  r9, r9, r12
0x399955de:  ldr.w  r4, [r3, r9, lsl #2]

Solution

  • If you don't use ARC, you should add an retain

    appId1 = [[idHelper stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] retain];
    

    as constructor stringByAddingPercentEscapesUsingEncoding: returns an autoreleased object