标签:style blog http color io os 使用 ar java
文章转载地址:http://www.headsky.org/?p=63
iOS4.0新加入了MFMessageComposeViewController和MFMessageComposeViewControllerDelegate,提供了发送短信的接口,可以像发送邮件那样不用跳出程序来发送短信. 介绍可参阅Message UI
Framework Reference
一些笔记:
若在iOS3.0上运行的话,会提示dyld: Symbol not found: _OBJC_CLASS_$_MFMessageComposeViewController .解决方案:
#pragma mark - #pragma mark SMS -(IBAction)showSMSPicker:(id)sender { // The MFMessageComposeViewController class is only available in iPhone OS 4.0 or later. // So, we must verify the existence of the above class and log an error message for devices // running earlier versions of the iPhone OS. Set feedbackMsg if device doesn’t support // MFMessageComposeViewController API. Class messageClass = (NSClassFromString(@”MFMessageComposeViewController”)); if (messageClass != nil) { // Check whether the current device is configured for sending SMS messages if ([messageClass canSendText]) { [self displaySMSComposerSheet]; } else { [UIAlertView quickAlertWithTitle:@"设备没有短信功能" messageTitle:nil dismissTitle:@"关闭"]; } } else { [UIAlertView quickAlertWithTitle:@"iOS版本过低,iOS4.0以上才支持程序内发送短信" messageTitle:nil dismissTitle:@"关闭"]; } } -(void)displaySMSComposerSheet { MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init]; picker.messageComposeDelegate = self; 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:%@" ,[web stringByEvaluatingJavaScriptFromString:@"document.title"] ,absUrl]; [absUrl release]; [self presentModalViewController:picker animated:YES]; [picker release]; } - (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result { switch (result) { case MessageComposeResultCancelled: LOG_EXPR(@”Result: SMS sending canceled”); break; case MessageComposeResultSent: LOG_EXPR(@”Result: SMS sent”); break; case MessageComposeResultFailed: [UIAlertView quickAlertWithTitle:@"短信发送失败" messageTitle:nil dismissTitle:@"关闭"]; break; default: LOG_EXPR(@”Result: SMS not sent”); break; } [self dismissModalViewControllerAnimated:YES]; }
IOS程序内发短信 MFMessageComposeViewController
标签:style blog http color io os 使用 ar java
原文地址:http://www.cnblogs.com/niit-soft-518/p/4021756.html