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];