I know this is not allowed in real apps in favor of user's privacy and security. But for pure academical purpose I am trying to send a message without presenting MessageComposer UI like this.
MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
if([MFMessageComposeViewController canSendText]) {
picker.recipients = [NSArray arrayWithObject:@"1234"];
picker.body = @"Hello";
[picker performSelector:@selector(smsComposeControllerSendStarted:) withObject:[UIButton buttonWithType:UIButtonTypeCustom]];
}
Nothing happens as a result. Not even a a failure exception on console. Neither I see a message on SMS app. The person I sent the message also didn't get it.
One Can find the list of iVars and Methods of MFMessageComposeViewController here.
And I wrote a quick code to verify if these are the items actually present in 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]);
}
It produces the following output:
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:
It appears to me that smsComposeControllerSendStarted:
method could be more of a delegate than actual function that starts the message sending. In the above method list none of the method signatures looks closer to sendMessage:
or something similar to a function that actually sends the message.
My Questions are:
1) Is that all really MFMessageComposeViewController
has under the hood. Or does it have some class clusters that are not accessible via runtime functions?
2) How to find out the actual messageSend method and it's implementation's class?
Any ideas would be greatly appreciated.
Thanks.