繁体   English   中英

目标C短信选项崩溃整个应用程序?

[英]objective C SMS option crashes the entire App?

我正在开发一个发送短信的iPhone应用程序,我正在使用XCode 4.2

基本上我需要它来生成一个正文并为收件人添加一个电话号码。

我在iPad上运行该应用程序,它崩溃了应用程序,当我查看代码并发现当我删除此行时,接收行正在解决问题,它完全正常并且它指向消息应用程序。

任何线索如何避免这个问题?

这是我正在使用的代码

MFMessageComposeViewController *sms = [[MFMessageComposeViewController alloc] init];
    if ([MFMessageComposeViewController canSendText]) {
        sms.recipients=[NSArray arrayWithObjects:@"1111111111"];
        sms.body= @"test";
        sms.messageComposeDelegate = self;
        [self presentModalViewController:sms animated:YES];
    }

日志:

GNU gdb 6.3.50-20050815 (Apple version gdb-1708) (Fri Sep 16 06:56:50 UTC 2011)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "--host=i386-apple-darwin --target=arm-apple-darwin".tty /dev/ttys000
sharedlibrary apply-load-rules all
target remote-mobile /tmp/.XcodeGDBRemote-692-73
Switching to remote-macosx protocol
mem 0x1000 0x3fffffff cache
mem 0x40000000 0xffffffff none
mem 0x00000000 0x0fff none
[Switching to process 7171 thread 0x1c03]
[Switching to process 7171 thread 0x1c03]
Re-enabling shared library breakpoint 1
Re-enabling shared library breakpoint 7
(gdb) 

我收到以下绿色错误:

Tread1 : Program Received signal :"EXC_BAD_ACCESS"

和以下警告(黄色)

Missing sentinel dispatch
sms.receipients=[NSArrayWithObjects:@"1111111111"];

不会起作用。 也不是

sms.recipients=[NSArray arrayWithObjects:@"1111111111"]

尝试

sms.recipients=[NSArray arrayWithObject:@"1111111111"];

arrayWithObjects需要一个nil终止的对象列表。 arrayWithObject只需要一个对象。

写这个作为答案,因为我没有权利发表评论。
我认为问题在于

sms.receipients=[NSArrayWithObjects:@"1111111111"];

应该是

 sms.receipients=[NSArray arrayWithObjects:@"1111111111"];

编辑:

  sms.receipients=[NSArray arrayWithObjects:@"1111111111",nil]; 

要么

  sms.receipients = [NSArray arrayWithObject:@"1111111111"];

现在您已根据收到的错误编辑了问题:

sms.recipients = [ NSArray arrayWithObjects: @"1111111111" ];

需要是:

sms.recipients = [ NSArray arrayWithObjects: @"1111111111", nil ];

你错过了nil sentinel,用于检测arrayWithObjects方法的变量参数的结尾。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM