简体   繁体   English

iPhone SDK - 在UIWebView中添加“添加到主屏幕”按钮

[英]iPhone SDK - Add a “Add to Home Screen” button in a UIWebView

I have a native iPhone app, which has a UIWebView component to it. 我有一个原生iPhone应用程序,它有一个UIWebView组件。 I am trying to see if I can replicate the " Add to Home Screen " button that is present in the tab bar options in Safari. 我试图看看我是否可以复制Safari中标签栏选项中的“ 添加到主屏幕 ”按钮。

Is this possible inside a UIWebView within a native app? 这是否可以在本机应用程序内的UIWebView中进行?

Thanks! 谢谢! Brett 布雷特

[I presume your question is about replicating the action associated with add to home screen, rather than replicating the appearance of the button itself (which being pedantic is what you actually wrote).] [我认为你的问题是复制与添加到主屏幕相关的动作,而不是复制按钮本身的外观(这是你实际写的迂腐)。

As others have said this isn't possible. 正如其他人所说,这是不可能的。

What you could do is programatically launch Safari from within your app and give it the URL of a page to load which is your page. 您可以做的是从您的应用程序中以编程方式启动Safari,并为其提供要加载的页面的URL,这是您的页面。

When your page is loaded it has some sort of animation and shows the user where the add to home screen button is and tell them to press it after clicking a link which is displayed in your web page. 加载页面时,它会显示某种动画,并向用户显示添加到主屏幕按钮的位置,并告诉他们在单击网页中显示的链接后按下该按钮。 When the users click on the link it takes them to whatever page it is that you would like saved to the desktop, and you hope they follow your instructions. 当用户点击链接时,它会将他们带到您希望保存到桌面的任何页面,并且您希望他们按照您的说明操作。

If you register your app to handle a proprietary url scheme the users can get back to your app from within Safari by clicking on a link using your app's url scheme. 如果您注册应用程序以处理专有网址方案,则用户可以通过使用应用程序的网址方案单击链接从Safari中返回您的应用程序。

The web pages that you seed Safari with must however be remote pages, you cannot give Safari a page in your app's bundle or that your app has downloaded as Safari cannot read pages from your app's sandbox. 然而,您为Safari播放的网页必须是远程页面,您不能在应用程序包中为Safari提供页面,或者您的应用程序已下载,因为Safari无法从应用程序的沙箱中读取页面。

The short answer is no, you can't. 简短的回答是不,你不能。 Apple does not let you. Apple不会让你。

Here's a similar question which may help you come up with other possibilities: Javascript for "Add to Home Screen" on iPhone? 这是一个类似的问题,可以帮助你提出其他可能性: iPhone上的“添加到主屏幕”的Javascript?

If I had to think of a work around off the top of my head, you could create an javascript pop-up which instructs them how to. 如果我不得不考虑到我的头脑中的工作,你可以创建一个javascript弹出窗口,指示他们如何。 It could say something like tap this button to go to mobile safari then tap action -> add to home screen. 它可以说点按这个按钮去手机游戏,然后点击动作 - >添加到主屏幕。

Execute the Javascript with UIWebView's method: 使用UIWebView的方法执行Javascript:

- (NSString *)stringByEvaluatingJavaScriptFromString:(NSString *)script

Hope this helps. 希望这可以帮助。

You can use UIActivityViewController with your url as the activity items 您可以将UIActivityViewController与您的网址一起用作活动项目

NSArray *activityItems = @[title, url];

And then you can exclude the activities that you don't want. 然后您可以排除您不想要的活动。 I think it´s the only way for now. 我认为这是目前唯一的方法。

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

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