DEV Community

Evan Lin
Evan Lin

Posted on • Originally published at evanlin.com on

LINE: Using liff.isApiAvailable() for LIFF compatibility in older LINE versions

(LIFF ShareTargetPickder Function Demonstration)

Preface

LIFF ShareTargetPickder is a very powerful function, which not only allows users to share information with friends more conveniently within LINE, but also allows users to share information with friends or chat groups through external browsers.

However, the support for this function on LINE must be after version 10.3.0. If the user's mobile LINE App version is not updated to the latest version, then this function may not be able to run properly.

Today's article will introduce a new API function liff.isApiAvailable() and how to use this API to allow new LIFF ShareTargetPickder to run on users with older versions of LINE, and provide a sample code and demonstration video for you.

Sample Code

https://github.com/kkdai/liff-template-go

Run a demo

Open this LIFF App

If you are on an iOS phone and open it through an older version of the LINE App (<10.2.0), you will see a warning message and it will open an external browser to open this LIFF URL.

You can watch the following video demonstration:

Code Explanation

(The complete code can be viewed at: https://github.com/kkdai/liff-template-go/blob/master/liff.html)

Here's a simple explanation:

-

if (liff.isApiAvailable('shareTargetPicker')) checks whether this API is currently supported.

  • If called in the LINE App, it will return different answers based on the different LINE Apps:
    • Returns False for versions less than 10.3.0.
    • Returns True for versions greater than or equal to 10.3.0.

- If called in an external browser, it will always return True.

If the version is not supported, it goes directly to 13, first displaying a warning window: "Your LINE App does not currently support Share Target Picker, the external browser will be started."

-

Then, it opens an external browser through liff.openWindow (through external: true), allowing users to use this function in another way.

Summary

Through liff.isApiAvailable(), developers who need to use LIFF ShareTargetPickder can allow some users to experience the power of LIFF ShareTargetPickder normally.

However, as the functions of LIFF gradually increase, perhaps there will be more surprising functions in the future, let's look forward to it?

References

Top comments (0)