这是一个短信分享的功能,很简单的,做了个笔记介绍一下,别的不说了,直接上代码。。。。。。
/**短信分享
*/
- (void)sharedByMessage
{
/**正常来说,id myObj = [[NSClassFromString(@"MySpecialClass") alloc] init];和
id myObj = [[MySpecialClass alloc] init];是一样的。但是,如果你的程序中并不存在MySpecialClass这个类,下面的写法会出错,而上面的写法只是返回一个空对象而已。因此,在某些情况下,可以使用NSClassFromString来进行你不确定的类的初始化。
*/
Class messageClass = (NSClassFromString(@"MFMessageComposeViewController"));
if (messageClass != nil) {
/**MFMessageComposeViewController提供了操作界面
使用前必须检查canSendText方法,若返回NO则不应将这个controller展现出来,而应该提示用户不支持发送短信功能.
*/
if ([messageClass canSendText]) {
[selfdisplaySMSComposerSheet];
}else{
UIAlertView *alert = [[UIAlertViewalloc]
initWithTitle:@"提醒"
message:@"您设备没有短信功能"
delegate:self
cancelButtonTitle:@"关闭"
otherButtonTitles:nil];
[alertshow];
}
}
}
-(void)displaySMSComposerSheet
{
MFMessageComposeViewController *picker = [[MFMessageComposeViewControlleralloc]init];
picker.messageComposeDelegate =self;
picker.body =@"我正在使用U箱超市,买日常所需挺方便的,推荐你也用一下。下载地址:http://m.uxiang.com/dl.htm?refer=appmm";
[selfpresentModalViewController:pickeranimated:YES];
}
#pragma mark --MFMessageComposeViewControllerDelegate
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
[self dismissModalViewControllerAnimated:YES];
if (result == MessageComposeResultCancelled){
}else if (result == MessageComposeResultSent){
UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"提醒"
message:@"短信发送成功,谢谢您对U箱的支持!"
delegate:self
cancelButtonTitle:@"确定"
otherButtonTitles:nil];
[av show];
}else if(result == MessageComposeResultFailed){
UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"提醒"
message:@"短信发送失败,是否重新发送?"
delegate:self
cancelButtonTitle:@"取消"
otherButtonTitles:@"重新发送", nil];
av.tag = 20;
[av show];
}
}