我正在开发一个应用程序,其中将用户确认邮件发送到用户电子邮件。 我能够收到这种格式的邮件“http://www.sample.com//Register.aspx?xxx(with parameters)”。 现在单击此邮件,我必须在 iOS9 中启动注册页面。
注意:如果我在 safari 应用程序打开时键入 Register.aspx://,但不是从电子邮件 URL。
我在 info.plist 和代码中做了以下事情 1.信息.plist
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>Register.aspx</string>
</array>
</dict>
</array>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>Register.aspx</string>
</array>
2.在我使用的应用委托(delegate)中:
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
BOOL canBeOpened = [[UIApplication sharedApplication]
canOpenURL:[NSURL URLWithString:@"Register.aspx://"]];
if (canBeOpened) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Test Message"
message:@"This is a url scheme"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
else{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Test Message"
message:@"This is not a url scheme"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
}
最佳答案
您将 URL 的错误部分注册为方案。您提供的示例具有 http
的标准 URL 方案。
第一个冒号之前的 URL 位是方案(通常是 http
或 https
)。要使用自定义方案,您需要为 URL 创建一个新方案并在您的电子邮件中输出该 URL,例如:
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>mycoolapp</string>
</array>
</dict>
</array>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>mycoolapp</string>
</array>
需要一封包含 URL 的电子邮件:
mycoolapp://www.sample.com/Register.aspx
关于ios - URL Scheme 在 iOS9 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37562236/