Ork*_*ade 17
试试这个.例如,您想要打开Instagram应用程序:
var instagramHooks = "instagram://user?username=johndoe"
var instagramUrl = NSURL(string: instagramHooks)
if UIApplication.sharedApplication().canOpenURL(instagramUrl!)
{
UIApplication.sharedApplication().openURL(instagramUrl!)
} else {
//redirect to safari because the user doesn't have Instagram
UIApplication.sharedApplication().openURL(NSURL(string: "http://instagram.com/")!)
}
Run Code Online (Sandbox Code Playgroud)
小智 6
在SecondApp中
转到SecondApp的plist文件,你需要添加一个带有字符串iOSDevTips的URL Schemes(当然你可以写另一个字符串.这取决于你).
2.在FirstApp中
使用以下操作创建一个按钮:
- (void)buttonPressed:(UIButton *)button
{
NSString *customURL = @"iOSDevTips://";
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:customURL]])
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:customURL]];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"URL error"
message:[NSString stringWithFormat:@"No custom URL defined for %@", customURL]
delegate:self cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[alert show];
}
}
Run Code Online (Sandbox Code Playgroud)
而已.现在,当您可以单击FirstApp中的按钮时,它应该打开SecondApp.
有关更多信息,请参阅此处
归档时间: |
|
查看次数: |
21440 次 |
最近记录: |