简体   繁体   English

自定义URL方案IOS

[英]Custom URL Scheme IOS

I have an application which will be launched from other apps which are mine too. 我有一个应用程序,它将从我的其他应用程序中启动。 But my purpose is to launch my app and do nothing with the URL. 但是我的目的是启动我的应用程序,并且不使用URL。 Its just a way of enabling the user to switch between apps without any data exchange. 这只是使用户无需任何数据交换即可在应用之间切换的一种方式。

Do I need to implement handleOpenURL or similar methods to handle the URL to filter out unwanted commands like apple mentions in Secure Coding guidelines , or just specifying the scheme in the info.plist (along with URL identifier and document role as Viewer) is enough secure considering the fact that I am not doing anything with the URL? 我是否需要实现handleOpenURL或类似方法来处理URL,以过滤掉不需要的命令,例如安全编码指南中的苹果提及,还是仅在info.plist中指定方案(以及URL标识符和文档角色作为Viewer)就足够安全了考虑到我对URL不做任何事情?

Yes, you need to implement application:handleOpenURL: or application:openURL:sourceApplication:annotation: , and return YES. 是的,您需要实现application:handleOpenURL:application:openURL:sourceApplication:annotation:并返回YES。 The second method is preferred according to Apple's docs. 根据Apple的文档,第二种方法是首选。

-(BOOL) application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{
  return YES;
}

You could additionally check the scheme, source application, or other conditions, and return YES or NO accordingly. 您还可以检查方案,源应用程序或其他条件,并相应地返回YES或NO。 If you have several of your apps communicating you can check for the source application or pass data using the annotation. 如果您有多个应用程序进行通信,则可以检查源应用程序或使用批注传递数据。

NSString* myappScheme = @"anindya";  // or even better read it from your plist
-(BOOL) application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{
  return [url.scheme isEqualToString: myappScheme];
}

As far as security is concerned, you don't really do anything else with the URL, so there's no problem. 就安全性而言,您实际上不会对该URL做任何其他事情,因此没有问题。 Apple's advice in this regard means if you get a URL from another app, you have to carefully parse it and assume it might be malicious. Apple在这方面的建议意味着,如果您从另一个应用程序获取URL,则必须仔细解析它并假定它可能是恶意的。 If you also check the source application you can be sure to only get data from your own apps. 如果您还检查源应用程序,则可以确保仅从自己的应用程序中获取数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM