最新调用短信界面发送短信
2014-02-27 15:34
211 查看
.h文件中
#import <UIKit/UIKit.h>
#import <MessageUI/MessageUI.h>
@interface ViewController :
UIViewController <MFMessageComposeViewControllerDelegate>
- (IBAction) sendMessagePressed:(id)sender;
@end
- (IBAction)sendMessagePressed:(id)sender {
Class messageClass = (NSClassFromString(@"MFMessageComposeViewController"));
if (messageClass != nil) {
// Check whether the current device is configured for sending SMS messages
if ([messageClass
canSendText]) {
[self
displaySMSComposerSheet];
}
else {
NSLog(@"设备没有短信功能");
}
}
else {
NSLog(@"iOS版本过低,iOS4.0以上才支持程序内发送短信");
}
}
-(void)displaySMSComposerSheet
{
MFMessageComposeViewController *picker = [[MFMessageComposeViewController
alloc] init];
picker.messageComposeDelegate =
self;
NSMutableString* absUrl = [[NSMutableString
alloc] initWithString:@"http://www.baidu.com"];
[absUrl replaceOccurrencesOfString:@"http://i.aizheke.com"
withString:@"http://m.aizheke.com"
options:NSCaseInsensitiveSearch
range:NSMakeRange(0, [absUrl
length])];
picker.body=[NSString
stringWithFormat:@"我在爱折客上看到:%@
可能对你有用,推荐给你!link:%@"
,@"http://www.baidu.com",
@"http://www.baidu.com"];
picker.recipients = [NSArray
arrayWithObjects:@"18079177441",
nil];
//[self presentModalViewController:picker animated:YES];
[self
presentViewController:picker animated:YES
completion:nil];
}
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller
didFinishWithResult:(MessageComposeResult)result {
switch (result)
{
case
MessageComposeResultCancelled:
NSLog(@"Result: SMS sending canceled");
break;
case
MessageComposeResultSent:
NSLog(@"Result: SMS sent");
break;
case
MessageComposeResultFailed:
NSLog(@"短信发送失败");
break;
default:
NSLog(@"Result: SMS not sent");
break;
}
//[self dismissModalViewControllerAnimated:YES];
[self
dismissViewControllerAnimated:YES
completion:nil];
}
#import <UIKit/UIKit.h>
#import <MessageUI/MessageUI.h>
@interface ViewController :
UIViewController <MFMessageComposeViewControllerDelegate>
- (IBAction) sendMessagePressed:(id)sender;
@end
- (IBAction)sendMessagePressed:(id)sender {
Class messageClass = (NSClassFromString(@"MFMessageComposeViewController"));
if (messageClass != nil) {
// Check whether the current device is configured for sending SMS messages
if ([messageClass
canSendText]) {
[self
displaySMSComposerSheet];
}
else {
NSLog(@"设备没有短信功能");
}
}
else {
NSLog(@"iOS版本过低,iOS4.0以上才支持程序内发送短信");
}
}
-(void)displaySMSComposerSheet
{
MFMessageComposeViewController *picker = [[MFMessageComposeViewController
alloc] init];
picker.messageComposeDelegate =
self;
NSMutableString* absUrl = [[NSMutableString
alloc] initWithString:@"http://www.baidu.com"];
[absUrl replaceOccurrencesOfString:@"http://i.aizheke.com"
withString:@"http://m.aizheke.com"
options:NSCaseInsensitiveSearch
range:NSMakeRange(0, [absUrl
length])];
picker.body=[NSString
stringWithFormat:@"我在爱折客上看到:%@
可能对你有用,推荐给你!link:%@"
,@"http://www.baidu.com",
@"http://www.baidu.com"];
picker.recipients = [NSArray
arrayWithObjects:@"18079177441",
nil];
//[self presentModalViewController:picker animated:YES];
[self
presentViewController:picker animated:YES
completion:nil];
}
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller
didFinishWithResult:(MessageComposeResult)result {
switch (result)
{
case
MessageComposeResultCancelled:
NSLog(@"Result: SMS sending canceled");
break;
case
MessageComposeResultSent:
NSLog(@"Result: SMS sent");
break;
case
MessageComposeResultFailed:
NSLog(@"短信发送失败");
break;
default:
NSLog(@"Result: SMS not sent");
break;
}
//[self dismissModalViewControllerAnimated:YES];
[self
dismissViewControllerAnimated:YES
completion:nil];
}
相关文章推荐
- Android调用系统短信发送界面并预设接收号码、短信内容
- 调用系统界面发送短信和邮件
- Android调用系统发送短信界面
- Android调用系统存储联系人界面,以及系统短信发送
- Android调用系统发送短信界面
- Android 调用系统发送短信界面,预设号码和短信内容
- 安卓调用系统短信界面发送短信
- iOS 调用系统短信、邮件发送界面
- Android Intent调用发送短信界面
- 在android里如何代码调用系统短信发送界面
- Android 调用系统发送短信界面,预设号码和短信内容
- H5APP 调用手机短信发送界面
- 调用系统界面,给指定的号码发送短信,附带短信内容
- 调用拨打电话界面、直接拨打电话、调用发送短信的界面、调用系统浏览器
- android调用系统发送短信 和 已发送短信界面
- 0108 Activity的生命周期(二)+显示文本的几种方法+调用发送短信(Intent)
- android 实现发送彩信方法 (MMS),非调用系统彩信界面
- android中调用系统的发送短信、发送邮件、打电话功能
- java调用C# webservice短信猫发送短信
- 第73章、再识Intent-调用发送短信程序(从零开始学Android)