發(fā)郵件、發(fā)信息罢猪、打電話

由于不知道怎么設(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;

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末备闲,一起剝皮案震驚了整個濱河市晌端,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌恬砂,老刑警劉巖咧纠,帶你破解...
    沈念sama閱讀 218,284評論 6 506
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異泻骤,居然都是意外死亡漆羔,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,115評論 3 395
  • 文/潘曉璐 我一進(jìn)店門狱掂,熙熙樓的掌柜王于貴愁眉苦臉地迎上來演痒,“玉大人,你說我怎么就攤上這事趋惨∧袼常” “怎么了?”我有些...
    開封第一講書人閱讀 164,614評論 0 354
  • 文/不壞的土叔 我叫張陵器虾,是天一觀的道長讯嫂。 經(jīng)常有香客問我,道長兆沙,這世上最難降的妖魔是什么欧芽? 我笑而不...
    開封第一講書人閱讀 58,671評論 1 293
  • 正文 為了忘掉前任,我火速辦了婚禮葛圃,結(jié)果婚禮上千扔,老公的妹妹穿的比我還像新娘。我一直安慰自己装悲,他們只是感情好昏鹃,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,699評論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著诀诊,像睡著了一般洞渤。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上属瓣,一...
    開封第一講書人閱讀 51,562評論 1 305
  • 那天载迄,我揣著相機(jī)與錄音讯柔,去河邊找鬼。 笑死护昧,一個胖子當(dāng)著我的面吹牛魂迄,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播惋耙,決...
    沈念sama閱讀 40,309評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼捣炬,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了绽榛?” 一聲冷哼從身側(cè)響起湿酸,我...
    開封第一講書人閱讀 39,223評論 0 276
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎灭美,沒想到半個月后推溃,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,668評論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡届腐,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,859評論 3 336
  • 正文 我和宋清朗相戀三年铁坎,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片犁苏。...
    茶點(diǎn)故事閱讀 39,981評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡硬萍,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出傀顾,到底是詐尸還是另有隱情襟铭,我是刑警寧澤,帶...
    沈念sama閱讀 35,705評論 5 347
  • 正文 年R本政府宣布短曾,位于F島的核電站,受9級特大地震影響赐劣,放射性物質(zhì)發(fā)生泄漏嫉拐。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,310評論 3 330
  • 文/蒙蒙 一魁兼、第九天 我趴在偏房一處隱蔽的房頂上張望婉徘。 院中可真熱鬧,春花似錦咐汞、人聲如沸盖呼。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,904評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽几晤。三九已至,卻和暖如春植阴,著一層夾襖步出監(jiān)牢的瞬間蟹瘾,已是汗流浹背圾浅。 一陣腳步聲響...
    開封第一講書人閱讀 33,023評論 1 270
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留憾朴,地道東北人狸捕。 一個月前我還...
    沈念sama閱讀 48,146評論 3 370
  • 正文 我出身青樓,卻偏偏與公主長得像众雷,于是被迫代替她去往敵國和親灸拍。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,933評論 2 355

推薦閱讀更多精彩內(nèi)容