简体   繁体   中英

How to invoke local peripheral device from web script

I am confused about invoking local app from web site. Is there any way to start an ipad/iphone app from web scripts? I remember that there is ActiveX with IE which could start a local device such as a camera or printer. JavaScript could invoke ActiveX. But there is no activeX in iOS. Here is my problem: How could I start local device from a webpage? Does anyone have the same problem? I have one method but I don't know if it is feasible:

  1. UIWebView could execute JavaScript by stringByEvaluatingJavaScriptFromString.
  2. write a function in a page with JavaScript, which responds to an event on the page (button click, etc.), then change the state.
  3. start a thread to inquire the state. When the state changes , invoke local apps.

Is that possible or any better way ?

If you wish to open your app from Safari browser from you iPad then there is a method to do so. Add the following tags in your app's info.plist file:

<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleURLName</key>
        <string>com.companyname.appname</string>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>openApp</string>
        </array>
    </dict>
</array>

Save the plist file and now on the web page put openApp:// in place of the link when user clicks the desired button. This won't be helpful if you try to implement it in your own app in a web view. But it will work from Safari browser from your iPad or from any other app.

I hope this is helpful.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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