由于iOS 5.1上的Xcode 4.3在设备上启动/安装应用程序时调试非常慢,我使用的启动模拟器要快得多。 (请参阅此问题https://stackoverflow.com/questions/11541288/xcode-4-3-with-ios5-1-pauses-about-10secs-when-debug-starts-simulator-starts-i)
所以我需要做的就是这样:
MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
picker.messageComposeDelegate = delegate;
NSString *s = @"1234567";
picker.recipients =[NSArray arrayWithObject: s];
picker.body =smsTxt;
if (simulationMode) {
MessageComposeResult result = MessageComposeResultSent; <-----------
[delegate messageComposeViewController:picker didFinishWithResult: result];
} else
[delegate presentModalViewController:picker animated:YES];
现在的问题是,在iOS-Simulator上执行时,MFMessageComposeViewController无法实例化,并且总是产生nil。
有没有办法在iOS模拟器上创建另一个对象MyOwnMFMessageComposeViewController,它与MFMessageComposeViewController兼容,可以像MFMessageComposeViewController一样传递?
这样的事情:
MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
picker.messageComposeDelegate = delegate;
NSString *s = @"1234567";
picker.recipients =[NSArray arrayWithObject: s];
picker.body =smsTxt;
if (simulationMode) {
MyOwnMFMessageComposeViewController *mypicker = [[MFMessageComposeViewController alloc] init];
mypicker.messageComposeDelegate = delegate;
NSString *s = @"1234567";
mypicker.recipients =[NSArray arrayWithObject: s];
mypicker.body =smsTxt;
MessageComposeResult result = MessageComposeResultSent;
picker = (MFMessageComposeViewController) mypicker;
[delegate messageComposeViewController:picker didFinishWithResult: result];
} else
[delegate presentModalViewController:picker animated:YES];
答案 0 :(得分:1)
您正在寻找的内容称为“模拟对象”,通常用于测试驱动开发。基本上你要做的是创建MFMessageComposeViewController的子类。这个子类与mfmessagecomposeviewcontroller完全相同,除了你还创建实例变量以显示发生的事情。
所以例如当你的委托调用messageComposeViewController:didFinishWithResult时。模拟对象可能存储结果以及该方法已被触发的标志。请注意,这实际上不会发送任何内容,而只是告诉您已触发的委托和实际对象将起作用。