您的位置:首页 > 编程语言

Iphone的发送短信-邮件-打电话代码示例

2012-01-31 18:21 435 查看
Maphttp://maps.google.com/maps?q=ShanghaiEmailmailto://myname@google.com
Teltel://10086
Msgsms://10086


openURL的使用方法:


CODE:

[[UIApplicationsharedApplication]openURL:[NSURLURLWithString:appString]];


除此之外,还可以自己定义URL,方法如下:

CODE:

打开info.plist,添加一项URLtypes
展开URLtypes,再展开Item1,将Item1下的URLidentifier修改为URLScheme
展开URLScheme,将Item1的内容修改为myapp
其他程序可通过myapp://访问此自定义URL


+(
void
)alert:(NSString*)msg


{

UIAlertView*alertView=[[[UIAlertViewalloc]initWithTitle:msgmessage:@
""
delegate:selfcancelButtonTitle:@
"OK"
otherButtonTitles:nil,nil]autorelease];

[alertViewshowWithBackground];

}


+(NSString*)cleanPhoneNumber:(NSString*)phoneNumber

{

NSString*number=[NSStringstringWithString:phoneNumber];

NSString*number1=[[[numberstringByReplacingOccurrencesOfString:@
""
withString:@
""
]

//stringByReplacingOccurrencesOfString:@"-"withString:@""]

stringByReplacingOccurrencesOfString:@
"("
withString:@
""
]

stringByReplacingOccurrencesOfString:@
")"
withString:@
""
];


return
number1;

}


+(
void
)makeCall:(NSString*)phoneNumber

{

NSString*numberAfterClear=[selfcleanPhoneNumber:phoneNumber];


NSURL*phoneNumberURL=[NSURLURLWithString:[NSStringstringWithFormat:@
"tel:%@"
,numberAfterClear]];

NSLog(@
"makecall,URL=%@"
,phoneNumberURL);


[[UIApplicationsharedApplication]openURL:phoneNumberURL];

}


拔打前会有提示,并且拔打结束后返回到自己的应用程序

[[UIApplicationsharedApplication]openURL:[NSURLURLWithString:@"telprompt://10086"]];

直接拔打,不会提示,拔打结束后停留在电话应用上

[[UIApplicationsharedApplication]openURL:[NSURLURLWithString:@"tel://10086"]];

+(
void
)sendSms:(NSString*)phoneNumber

{


NSString*numberAfterClear=[selfcleanPhoneNumber:phoneNumber];


NSURL*phoneNumberURL=[NSURLURLWithString:[NSStringstringWithFormat:@
"sms:%@"
,numberAfterClear]];

NSLog(@
"sendsms,URL=%@"
,phoneNumberURL);

[[UIApplicationsharedApplication]openURL:phoneNumberURL];

}


+(
void
)sendEmail:(NSString*)phoneNumber

{

NSURL*phoneNumberURL=[NSURLURLWithString:[NSStringstringWithFormat:@
"mailto:%@"
,phoneNumber]];

NSLog(@
"sendsms,URL=%@"
,phoneNumberURL);

[[UIApplicationsharedApplication]openURL:phoneNumberURL];

}


+(
void
)sendEmail:(NSString*)tocc:(NSString*)ccsubject:(NSString*)subjectbody:(NSString*)body

{

NSString*str=[NSStringstringWithFormat:@
"mailto:%@?cc=%@&subject=%@&body=%@"
,

to,cc,subject,body];


str=[strstringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];


[[UIApplicationsharedApplication]openURL:[NSURLURLWithString:str]];


}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: