如何从电子邮件中打开我的iPhone应用程序?

时间:2014-11-19 12:15:16

标签: ios objective-c iphone email safari

要求我必须通过电子邮件中的链接打开我的应用。

为此我在电子邮件按钮操作上使用以下代码

- (IBAction)sendMail:(id)sender {

    // From within your active view controller
    if([MFMailComposeViewController canSendMail]) {
        MFMailComposeViewController *mailCont = [[MFMailComposeViewController alloc] init];
        mailCont.mailComposeDelegate = self;// Required to invoke mailComposeController when send

        [mailCont setSubject:@“Email];
        [mailCont setToRecipients:[NSArray arrayWithObject:@"Receipts"]];

        NSMutableString *mutableString=[[NSMutableString alloc] initWithString:@"Hi,<br>\n"];

        [mutableString appendString:[NSString stringWithFormat:@"<br> <a href=\"PracticeExample://\">Open my app</a></br>"]];





        NSString *emailBody =[NSString stringWithFormat:@"<html><body>%@</br></body></html>",mutableString];

        [mailCont setMessageBody:emailBody isHTML:YES];

        [self presentViewController:mailCont animated:YES completion:nil];
    }
}

当我点击我的电子邮件中的“打开我的应用程序”链接时,它正在打开Safari,但应用程序未打开并显示“safari无法打开页面......”文本。

如果我在safari地址栏中观察到网站名称就像这个“PracticeExample //”,如果我将其更改为“PracticeExample://”,那么它会打开我的应用程序。

注意:“PracticeExample”是我使用以下链接在Plist中的自定义网址方案中注册。http://iosdevelopertips.com/cocoa/launching-your-own-application-via-a-custom-url-scheme.html

**还有一个问题如果app没有安装在设备中,如何打开AppStore?**

1 个答案:

答案 0 :(得分:0)

我认为您可能需要设置自定义统一类型标识符(UTI)。看看这个解决方案。我相信this就是您正在寻找的答案。

此外,可能需要查看NSKeyedArchiver的Apple documentation,这是自定义文件类型的关键。您将能够使用此功能读取和写入某个目录中的文件。

相关问题