由于不知道怎么設(shè)置簡述格式捕虽,無法上傳代碼文件,所以就隨便貼上代碼
導(dǎo)入MessageUI.frameWork
#import@interface SimpleCallViewController : UIViewController
/**
*? 打電話
*
*? @param number? ? ? ? ? ? ? ? ? 電話號碼
*? @param inViewController? ? 需要打電話的控制器
*/
+(void)call:(NSString *)number inViewController:(UIViewController *)vc failBlock:(void(^)())failBlock;
/**
*? 發(fā)短信
*
*? @param message? ? ? ? ? ? ? ? ? 短信內(nèi)容
*? @param inViewController? ? 需要發(fā)短信的控制器
*/
+(void)sendMessage:(NSString *)message numb:(NSString *)number inViewController:(UIViewController *)vc failBlock:(void(^)())failBlock;
/**
*? 發(fā)郵件
*
*? @param message? ? ? ? ? ? ? ? ? 短信內(nèi)容
*? @param inViewController? ? 需要發(fā)短信的控制器
*/
+(void)sendMailInViewController:(UIViewController *)vc failBlock:(void(^)())failBlock;
@end
#import "SimpleCallViewController.h"#import@interface SimpleCallViewController (){
UIViewController *viewController;
}
@property (nonatomic,strong) UIWebView *webView;
@end
@implementation SimpleCallViewController
- (instancetype)init
{
self = [super init];
if (self) {
_webView=[[UIWebView alloc] init];
}
return self;
}
-(void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
[self removeFromParentViewController];
}
+(void)call:(NSString *)number inViewController:(UIViewController *)vc failBlock:(void(^)())failBlock
{
//撥打電話
NSURL *url=[NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",number]];
//? 方法一坡脐、使用openURL這個API打電話結(jié)束后泄私,返回的是系統(tǒng)的撥打電話界面
BOOL canOpen = [[UIApplication sharedApplication] canOpenURL:url];
if(!canOpen){//不能打開
if(failBlock!=nil) failBlock(); return;
}
//方法二? 通話結(jié)束后留在自己的應(yīng)用界面
/**
*? UIWebView*callWebview =[[UIWebView alloc] init];
*? NSURL *telURL =[NSURL URLWithString:@"tel:10010"];
*? [callWebview loadRequest:[NSURLRequest requestWithURL:telURL]];
*? [self.view addSubview:callWebview];
*/
SimpleCallViewController *mediaVC=[[SimpleCallViewController alloc] init];
mediaVC.view.frame=CGRectZero;
mediaVC.view.alpha=.0f;
[vc addChildViewController:mediaVC];
[vc.view addSubview:mediaVC.view];
NSURLRequest *request=[NSURLRequest requestWithURL:url];
[mediaVC.webView loadRequest:request];
//? 方法三 不一定通過App store
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"telprompt://10010"]];
}
+(void)sendMessage:(NSString *)message numb:(NSArray *)numberArr inViewController:(UIViewController *)vc failBlock:(void(^)())failBlock{
//? ? 方法一 發(fā)送固定短信
NSString *tel = [NSString stringWithFormat:@"sms://%@",numberArr];
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:tel]];//發(fā)短信
//? ? 方法二 發(fā)送任意短信
if ([MFMessageComposeViewController canSendText]) {
MFMessageComposeViewController *messageVc = [[MFMessageComposeViewController alloc] init];
messageVc.recipients = numberArr;? //支持群發(fā)
messageVc.body = message;? ? ? ? ? //短信內(nèi)容
messageVc.messageComposeDelegate = self;
[vc presentViewController:messageVc animated:YES completion:nil];
[[[[messageVc viewControllers] lastObject] navigationItem] setTitle:@"測試短信"];//修改短信界面標(biāo)題
}
else
NSLog(@"can't send message");
}
#pragma mark ****** MFMessageComposeViewControllerDelegate ******
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result{
[controller dismissViewControllerAnimated:NO completion:nil];//關(guān)鍵的一句? 不能為YES
switch ( result ) {
case MessageComposeResultCancelled:
NSLog(@"發(fā)送取消");
break;
case MessageComposeResultFailed:// send failed
NSLog(@"發(fā)送成功");
break;
case MessageComposeResultSent:
NSLog(@"發(fā)送失敗");
break;
default:
break;
}
}
/** *? 發(fā)郵件 */+ (void)sendMailInViewController:(UIViewController *)vc failBlock:(void(^)())failBlock;{? ??
Class mailClass = (NSClassFromString(@"MFMailComposeViewController"));?
if (mailClass != nil)?
?? {
? ? ? ? if ([mailClass canSendMail])
? ? ? ? {?
?? ? ? ? ? MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];?
?? ? ? ? ? //? ? 字體顏色?
?? ? ? ? ? //? ? mc.navigationBar.tintColor = [UIColor colorWithRed:209.0/255 green:183.0/255 blue:126.0/255 alpha:1.0];
? ? ? ? ? ? //? ? 代理?
?? ? ? ? ? mc.mailComposeDelegate = self;
? ? ? ? ? ?//? ? 主題
?? ? ? ? ? ?[mc setSubject:@"Hello, World!"];
? ? ? ? ? ? //? ? 主送
? ? ? ? ? ? [mc setToRecipients:[NSArray arrayWithObjects:@"502748959@qq.com", nil]];
? ? ? ? ? ? //? ? 抄送
? ? ? ? ? ? [mc setCcRecipients:[NSArray arrayWithObject:@"wenfuhoo@163.com"]];?
?? ? ? ? ? //? ? 密送
? ? ? ? ? ? [mc setBccRecipients:[NSArray arrayWithObject:@"1945028197@qq.com"]];
? ? ? ? ? ? //? ? 內(nèi)容 1
? ? ? ? ? ? [mc setMessageBody:@"Watson!!!\n\nCome here, I need you!" isHTML:NO];
? ? ? ? ? ? //? ? 內(nèi)容 2
? ? ? ? ? ? // [mc setMessageBody:@"Hello, Joe!?What do you know?" ?isHTML:YES];?
?? ? ? ? ? //? ? 內(nèi)容 3?
?? ? ? ? ? //? ? ? ? ? ? [mailCompose setMessageBody:[self formalEmailBody] isHTML:YES];?
?? ? ? ? ? // 添加圖片
? ? ? ? ? ? UIImage *addPic = [UIImage imageNamed:@""];
? ? ? ? ? ? NSData *imageData = UIImagePNGRepresentation(addPic);? ? ? ? ? ? // png? ? ? ? ? ??
? ? ? ? // NSData *imageData = UIImageJPEGRepresentation(addPic, 1);? ? // jpeg?
? ? ? ? ? ? ?[mc addAttachmentData: imageData mimeType: @"" fileName: @""];? ??
? ? ? ? ? ? ? [vc presentViewController:mc animated:YES completion:nil]; ??
? ? }??
? ? ? else
? ? ? ? {
?? ? ? ? ? NSLog(@"無法發(fā)送郵件,請?jiān)凇班]箱”應(yīng)用中設(shè)置您的郵箱帳戶!");
? ? ? ? }?
?? }
}
#pragma mark ****** MFMailComposeViewControllerDelegate ******
- (void)mailComposeController:(MFMailComposeViewController*)controller
didFinishWithResult:(MFMailComposeResult)result
error:(NSError*)error {
switch (result)
{
case MFMailComposeResultCancelled:
NSLog(@"Mail send canceled...");
break;
case MFMailComposeResultSaved:
NSLog(@"Mail saved...");
break;
case MFMailComposeResultSent:
NSLog(@"Mail sent...");
break;
case MFMailComposeResultFailed:
NSLog(@"Mail send errored: %@...", [error localizedDescription]);
break;
default:
break;
}
[controller dismissViewControllerAnimated:YES completion:nil];
}
- (NSString *)formalEmailBody
{
NSString *strBody;
/// 讀取feedback.html文件
NSString *fdFile = [[NSBundle mainBundle] pathForResource:@"feedback"
ofType:@"html"];
NSString *strFeedBack = [NSString stringWithContentsOfFile:fdFile
encoding:NSUTF8StringEncoding
error:nil];
if (strFeedBack.length > 0){
/// 獲取APP名稱
NSDictionary *appInfo = [[NSBundle mainBundle] localizedInfoDictionary];
NSString *appName = [appInfo objectForKey:@"CFBundleDisplayName"];
/// 獲取APP版本號
NSString *appVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"];
/// 獲取設(shè)備類型及OS版本
NSString *devName = [UIDevice currentDevice].model;
NSString *sysVersion = [UIDevice currentDevice].systemVersion;
strBody = [NSString stringWithFormat:strFeedBack,devName,sysVersion,appName,appVersion];
}
else
strBody = @"";
return strBody;
}
-(void)dealloc
{
self.webView=nil;
}