IOS call system texting and calling function
iOS phone Smsinterface Internet class
Let's start by introducing one of the simplest methods:
Call Call function
[[Uiapplicationsharedapplication] Openurl:[nsurl urlwithstring:@ "tel://10086"];
Call to send SMS function
[[UIApplication sharedapplication]openurl:[nsurl urlwithstring:@ "sms://10000"];
The above text messaging function is to call the system interface, the following is a click to implement a button to send text messages directly, equivalent to send the background, can be on the software store, not sure. Relative recommendations, try to use the first one.
First import mfmessagecomposeviewcontrollerdelegate This agent, implement the method inside
-(void) Messagecomposeviewcontroller: (Mfmessagecomposeviewcontroller *) Controllerdidfinishwithresult: ( Messagecomposeresult) Result {
//Notifies users about errors associated with the interface switch (result) { case MessageComposeResultCancelled: if (DEBUG) NSLog(@"Result: canceled"); break; case MessageComposeResultSent: if (DEBUG) NSLog(@"Result: Sent"); break; case MessageComposeResultFailed: if (DEBUG) NSLog(@"Result: Failed"); break; default: break; }
}
Mass SMS:
-(ibaction) sendsms {
BOOL cansendsms = [Mfmessagecomposeviewcontroller cansendtext];
NSLog (@ "Can send SMS [%d]", cansendsms);
if (cansendsms) {
MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init]; picker.messageComposeDelegate = self; picker.navigationBar.tintColor = [UIColor blackColor]; picker.body = @"test"; picker.recipients = [NSArray arrayWithObject:@"10086"]; [self presentModalViewController:picker animated:YES]; [picker release];
}
}
Send a text message to a person:
Get content from a Web page
-(void) Displaysmscomposersheet
{
MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];picker.messageComposeDelegate = self;UIWebView *web = nil;NSMutableString* absUrl = [[NSMutableString alloc] initWithString:web.request.URL.absoluteString];[absUrl replaceOccurrencesOfString:@"http://i.aizheke.com" withString:@"http://m.aizheke.com" options:NSCaseInsensitiveSearch range:NSMakeRange(0, [absUrl length])];picker.body=[NSString stringWithFormat:@"我在爱折客上看到:%@ 可能对你有用,推荐给你!link:%@",[webstringByEvaluatingJavaScriptFromString:@"document.title"],absUrl];
[Absurl release];
[Self presentmodalviewcontroller:picker animated:yes];
[Picker release];
}
Event binding Send SMS
-(Ibaction) Showsmspicker: (ID) Sender {
Class messageClass = (NSClassFromString(@"MFMessageComposeViewController"));if (messageClass != nil) { if ([messageClass canSendText]) { [self displaySMSComposerSheet]; } else {
Device does not have SMS function
}}else {
iOS version is too low for iOS4.0 to send SMS within the program
}
}
iOS Issue summary: 2015-1-9 iOS call system texting and calling function