我知道在真实的应用程序中,这是不允许的,因为需要保护用户的隐私和安全。但出于纯学术目的,我正在尝试像这样发送消息而不显示MessageComposer UI。
MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
if([MFMessageComposeViewController canSendText]) {
picker.recipients = [NSArray arrayWithObject:@"1234"];
picker.body = @"Hello";
[picker performSelector:@selector(smsComposeControllerSendStarted:) withObject:[UIButton buttonWithType:UIButtonTypeCustom]];
}
没有任何反应。控制台上甚至没有失败异常。短信应用程序也没有显示任何消息。我发送的信息的接收者也没有收到。
可以在此处找到MFMessageComposeViewController的iVars和Methods列表。
我编写了一个快速代码来验证这些是否实际存在于MFMessageComposeViewController中。
uint varCount = 0;
Class cls= [MFMessageComposeViewController class];
Ivar *vars = class_copyIvarList(cls, &varCount);
for (uint i = 0; i < varCount; i++) {
Ivar var = vars[i];
const char* name = ivar_getName(var);
const char* typeEncoding = ivar_getTypeEncoding(var);
printf("iVar%i------------> %s\n",i+1,name);
}
free(vars);
Method *imps = class_copyMethodList(cls, &varCount);
for (uint i = 0; i < varCount; i++) {
SEL sel = method_getName(imps[i]);
printf("Method%i------------> %s\n",i+1,[(NSStringFromSelector(sel)) UTF8String]);
}
它生成以下输出:
iVar1------------> _messageComposeDelegate
iVar2------------> _recipients
iVar3------------> _body
iVar4------------> _subject
iVar5------------> _mutableAttachmentURLs
iVar6------------> _currentAttachedVideoCount
iVar7------------> _currentAttachedAudioCount
iVar8------------> _currentAttachedImageCount
iVar9------------> _temporaryAttachmentURLs
iVar10------------> _attachments
Method1------------> disableUserAttachments
Method2------------> setCurrentAttachedVideoCount:
Method3------------> setCurrentAttachedAudioCount:
Method4------------> setCurrentAttachedImageCount:
Method5------------> _MIMETypeForURL:
Method6------------> _isVideoMIMEType:
Method7------------> _isAudioMIMEType:
Method8------------> _isImageMIMEType:
Method9------------> mutableAttachmentURLs
Method10------------> _contentTypeForMIMEType:
Method11------------> _updateAttachmentCountForAttachmentURL:
Method12------------> _buildAttachmentInfoForAttachmentURL:andAlternameFilename:
Method13------------> temporaryAttachmentURLs
Method14------------> canAddAttachmentURL:
Method15------------> addAttachmentData:withAlternateFilename:
Method16------------> _setCanEditRecipients:
Method17------------> messageComposeDelegate
Method18------------> setMutableAttachmentURLs:
Method19------------> currentAttachedVideoCount
Method20------------> currentAttachedAudioCount
Method21------------> currentAttachedImageCount
Method22------------> setTemporaryAttachmentURLs:
Method23------------> dealloc
Method24------------> viewWillAppear:
Method25------------> initWithNibName:bundle:
Method26------------> automaticallyForwardAppearanceAndRotationMethodsToChildViewControllers
Method27------------> setModalPresentationStyle:
Method28------------> body
Method29------------> setSubject:
Method30------------> subject
Method31------------> setMessageComposeDelegate:
Method32------------> setBody:
Method33------------> addAttachmentURL:withAlternateFilename:
Method34------------> addAttachmentData:typeIdentifier:filename:
Method35------------> attachmentURLs
Method36------------> attachments
Method37------------> recipients
Method38------------> smsComposeControllerCancelled:
Method39------------> smsComposeControllerSendStarted:
Method40------------> setRecipients:
我认为smsComposeControllerSendStarted:
方法更像是代理而不是真正启动消息发送的功能。在上面的方法列表中,没有一种方法签名看起来更接近sendMessage:
或类似于实际发送消息的函数。
我的问题是:
1)这确实是MFMessageComposeViewController
在代码内部所拥有的全部内容吗?还是它有一些类群集,无法通过运行时函数访问?
2)如何找到实际的messageSend方法及其实现类?
任何想法都将不胜感激。
谢谢。