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

后端 未结 3 802
南笙
南笙 2020-12-06 07:30

I have a native iPhone app, which has a UIWebView component to it. I am trying to see if I can replicate the \"Add to Home Screen\" button that

相关标签:
3条回答
  • 2020-12-06 07:51

    You can use UIActivityViewController with your url as the activity items

    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.

    0 讨论(0)
  • 2020-12-06 07:55

    The short answer is no, you can't. Apple does not let you.

    Here's a similar question which may help you come up with other possibilities: Javascript for "Add to Home Screen" on iPhone?

    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. 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:

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

    Hope this helps.

    0 讨论(0)
  • 2020-12-06 08:08

    [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.

    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.

    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.

    0 讨论(0)
提交回复
热议问题