내 앱 내에서 Apple Mail 앱을 시작 하시겠습니까?
내가 이미 찾은 것은
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto:"]];
하지만 작곡가보기뿐만 아니라 메일 앱을 열고 싶습니다. 정상 또는 마지막 상태의 메일 앱만.
어떤 아이디어?
분명히 메일 응용 프로그램은 두 번째 URL 구성표를 지원합니다- message://
응용 프로그램에서 가져온 경우 특정 메시지를 열 수 있습니다. 메시지 URL을 제공하지 않으면 메일 응용 프로그램이 열립니다.
NSURL* mailURL = [NSURL URLWithString:@"message://"];
if ([[UIApplication sharedApplication] canOpenURL:mailURL]) {
[[UIApplication sharedApplication] openURL:mailURL];
}
NSString *recipients = @"mailto:first@example.com?cc=second@example.com,third@example.com&subject=Hello from California!";
NSString *body = @"&body=It is raining in sunny California!";
NSString *email = [NSString stringWithFormat:@"%@%@", recipients, body];
email = [email stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:email]];
원래 Amit 답변의 신속한 버전 :
스위프트 2 :
func openMailApp() {
let toEmail = "stavik@outlook.com"
let subject = "Test email".stringByAddingPercentEncodingWithAllowedCharacters(.URLHostAllowedCharacterSet()
let body = "Just testing ...".stringByAddingPercentEncodingWithAllowedCharacters(.URLHostAllowedCharacterSet()
if let
urlString = ("mailto:\(toEmail)?subject=\(subject)&body=\(body)")),
url = NSURL(string:urlString) {
UIApplication.sharedApplication().openURL(url)
}
}
스위프트 3.0 :
func openMailApp() {
let toEmail = "stavik@outlook.com"
let subject = "Test email".addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)
let body = "Just testing ...".addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)
if let
urlString = "mailto:\(toEmail)?subject=\(subject)&body=\(body)",
url = URL(string:urlString) {
UIApplication.shared().openURL(url)
}
}
다른 응용 프로그램을 시작하는 유일한 방법은 URL 체계를 사용하는 것이므로 메일을 여는 유일한 방법은 mailto : 체계를 사용하는 것입니다. 불행히도 귀하의 경우에는 항상 작성보기가 열립니다.
URL 스키마를 사용하여 작성보기를 열지 않고도 메일 앱을 열 수 있습니다. message://
실제 기기에서 앱을 실행하고 전화하세요.
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"your@email.com"]];
이 줄은 시뮬레이터에 영향을 미치지 않습니다.
URL 스키마를 알고있는 경우 iOS에서 모든 앱을 실행할 수 있습니다. 메일 앱 체계가 공개되어 있는지 모르지만 은밀하게 시도 할 수 있습니다.
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"message:message-id"]];
내가 이것에 대해 단서를 준 Farhad Noorzay에게 소품. Mail 앱 API의 리버스 엔지니어링입니다. 자세한 정보 : https://medium.com/@vijayssundaram/how-to-deep-link-to-ios-7-mail-6c212bc79bd9
Amit의 답변 확장 : 새 이메일이 시작된 메일 앱이 시작됩니다. 새 이메일이 시작되는 방법을 변경하려면 문자열을 편집하십시오.
//put email info here:
NSString *toEmail=@"supp0rt.fl0ppyw0rm@gmail.com";
NSString *subject=@"The subject!";
NSString *body = @"It is raining in sunny California!";
//opens mail app with new email started
NSString *email = [NSString stringWithFormat:@"mailto:%@?subject=%@&body=%@", toEmail,subject,body];
email = [email stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:email]];
Xamarin을 사용하여 iOS 애플리케이션을 개발하는 경우 메일 애플리케이션 작성기보기를 여는 데 해당하는 C #은 다음과 같습니다.
string email = "yourname@companyname.com";
NSUrl url = new NSUrl(string.Format(@"mailto:{0}", email));
UIApplication.SharedApplication.OpenUrl(url);
신속한 2.3 : 사서함 열기
UIApplication.sharedApplication().openURL(NSURL(string: "message:")!)
Swift 4 / 5 to open default Mail App without compose view. If Mail app is removed, it automatically shows UIAlert with options to redownload app :)
UIApplication.shared.open(URL(string: "message:")!, options: [:], completionHandler: nil)
You might want to use a scripting bridge. I used this method in my App to directly give the user the option to send e-mail notifications using the built in Mail.app. I also constructed an option to do this directly over SMTP as an alternate.
But since you want to use Mail.app method, you can find more information about how to do that solution by following this:
https://github.com/HelmutJ/CocoaSampleCode/tree/master/SBSendEmail
Good Luck!
It will open Default Mail App with composer view:
NSURL* mailURL = [NSURL URLWithString:@"mailto://"];
if ([[UIApplication sharedApplication] canOpenURL:mailURL]) {
[[UIApplication sharedApplication] openURL:mailURL];
}
It will open Default Mail App:
NSURL* mailURL = [NSURL URLWithString:@"message://"];
if ([[UIApplication sharedApplication] canOpenURL:mailURL]) {
[[UIApplication sharedApplication] openURL:mailURL];
}
Swift 5 version:
if let mailURL = URL(string: "message:") {
if UIApplication.shared.canOpenURL(mailURL) {
UIApplication.shared.open(mailURL, options: [:], completionHandler: nil)
}
}
In Swift:
let recipients = "someone@gmail.com"
let url = NSURL(string: "mailto:\(recipients)")
UIApplication.sharedApplication().openURL(url!)
참고URL : https://stackoverflow.com/questions/8821934/launch-apple-mail-app-from-within-my-own-app
'Development Tip' 카테고리의 다른 글
모델에 숫자를 사용하는 Angularjs ng-options가 초기 값을 선택하지 않습니다. (0) | 2020.12.02 |
---|---|
셸 명령의 출력을 버퍼링 해제하는 방법은 무엇입니까? (0) | 2020.12.02 |
SQLITE 데이터베이스 파일 버전을 찾는 방법 (0) | 2020.12.02 |
XCode 6.3 경고 : 속성 합성 (0) | 2020.12.02 |
전략 패턴과 명령 패턴의 차이점 (0) | 2020.12.02 |