iOS上的openURL问题

时间:2013-05-30 15:52:47

标签: ios objective-c ios6

我目前遇到了Xcode中[[UIApplication sharedApplication] openURL:[NSURL URLWithString:]]方法的一些问题:

在我的iPhone应用程序中,我从服务器下载.txt文件并解析它:

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

“allLines”是一个包含.txt文件所有内容的数组。

“appId1”是一个NSString。

在上面的代码中,我将appId1设置为此网址:http://itunes.apple.com/app/id343200656/

在我的UIViewController的.xib中,我用UIButton调用以下方法:

- (IBAction)downloadApp:(id)sender { 

    NSLog(@"downloadApp1");

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

此方法应打开移动App Store并从链接显示应用程序。

但每次我调用此方法时,应用程序崩溃,我无法弄清楚原因。

任何人都可以帮我解决这个问题吗?非常感谢你!

编辑:这是崩溃日志。遗憾。

`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`

应用程序在“0x39df704e:ldrbne r3,[r1],#1”崩溃时出现EXC_BAD_ACCESS(代码= 1,地址= 0x0)。

这是启用了僵尸对象的崩溃日志:

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]

1 个答案:

答案 0 :(得分:1)

如果您不使用ARC,则应添加保留

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

作为构造函数stringByAddingPercentEscapesUsingEncoding:返回一个自动释放的对象