按鈕復(fù)制與發(fā)短信

1.點(diǎn)擊按鈕復(fù)制

UIPasteboard *pab = [UIPasteboard generalPasteboard];

NSString *string = @"測試";

[pab setString:string];

if (pab == nil) {

[SVProgressHUD showErrorWithStatus:@"復(fù)制失敗"];

[SVProgressHUD dismissWithDelay:.3];

}else

{

[SVProgressHUD showSuccessWithStatus:@"已復(fù)制"];

[SVProgressHUD dismissWithDelay:.3];

}

2.調(diào)用系統(tǒng)發(fā)送短信

實(shí)現(xiàn)此功能,一般使用程序內(nèi)調(diào)用系統(tǒng)。首先將頭文件引入

#import<MessageUI/MessageUI.h>

實(shí)現(xiàn)代碼

if( [MFMessageComposeViewController canSendText]) {

MFMessageComposeViewController * controller = [[MFMessageComposeViewController alloc] init];

controller.recipients = @[@"10086"];//發(fā)送短信的號碼,數(shù)組形式入?yún)?/p>

controller.navigationBar.tintColor = [UIColor redColor];

controller.body = @"body"; //此處的body就是短信將要發(fā)生的內(nèi)容

controller.messageComposeDelegate = self;

[self presentViewController:controller animated:YES completion:nil];

[[[[controller viewControllers] lastObject] navigationItem] setTitle:@"title"];//修改短信界面標(biāo)題

}

else {

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示信息"

message:@"該設(shè)備不支持短信功能"

delegate:nil

cancelButtonTitle:@"確定"

otherButtonTitles:nil, nil];

[alert show];

}

如要獲取發(fā)送狀態(tài),遵守代理MFMessageComposeViewControllerDelegate并實(shí)現(xiàn)代理方法

-(void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result {

[self dismissViewControllerAnimated:YES completion:nil];

switch (result) {

case MessageComposeResultSent:

//信息傳送成功

break;

case MessageComposeResultFailed:

//信息傳送失敗

break;

case MessageComposeResultCancelled:

//信息被用戶取消傳送

break;

default:

break;

}

}

如果想要發(fā)送短信之后留在短信頁面直接用openUrl

實(shí)現(xiàn)代碼

NSString *phoneStr = [NSString stringWithFormat:@"10086"];//發(fā)短信的號碼

NSString *smsContentStr = [NSString stringWithFormat:@"短信內(nèi)容"];

NSString *urlStr = [NSString stringWithFormat:@"sms://%@&body=%@ ", phoneStr, smsContentStr];

NSURL *url = [NSURL URLWithString:urlStr];

[[UIApplication sharedApplication] openURL:url];

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容