我正在开发一个发送短信的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
答案 0 :(得分:1)
sms.receipients=[NSArrayWithObjects:@"1111111111"];
无法运作。也不是
sms.recipients=[NSArray arrayWithObjects:@"1111111111"]
尝试
sms.recipients=[NSArray arrayWithObject:@"1111111111"];
arrayWithObjects需要一个nil终止的对象列表。 arrayWithObject只需要一个对象。
答案 1 :(得分:1)
将此作为答案,因为我没有权利发表评论 我认为问题在于
sms.receipients=[NSArrayWithObjects:@"1111111111"];
应该是
sms.receipients=[NSArray arrayWithObjects:@"1111111111"];
编辑:
sms.receipients=[NSArray arrayWithObjects:@"1111111111",nil];
或
sms.receipients = [NSArray arrayWithObject:@"1111111111"];
答案 2 :(得分:0)
现在您已根据收到的错误编辑了问题:
sms.recipients = [ NSArray arrayWithObjects: @"1111111111" ];
需要:
sms.recipients = [ NSArray arrayWithObjects: @"1111111111", nil ];
您错过nil
哨兵,用于检测arrayWithObjects
方法的变量参数的结尾。