# LIFF v2 API reference
# Client API
# Operating environment
For more information about supported operating environments for LIFF v2, see Overview in the LIFF documentation.
Which functions you can use depends on whether the LIFF app is opened in a LIFF browser or an external browser. For example, you can't use liff.scanCode()
in an external browser. For more information, see the descriptions for each client API.
For example, retrieving a user's profile information through a LIFF app isn't possible in most cases.
# LIFF SDK errors
LIFF SDK errors are returned in LiffError objects.
Example error
# LiffError object
code
String
Error code
message
String
Error message. Returned when the defined message exists.
# Error details
Error code | Description |
---|---|
400 | Problem with the request. Check the request parameters and JSON format. |
401 | Check that the authorization header is correct. |
403 | Not authorized to use the API. Confirm that your account or plan is authorized to use the API. |
429 | Make sure that you are within the rate limit for requests. |
500 | Temporary error on the API server. |
INIT_FAILED | Failed to init LIFF SDK. |
INVALID_ARGUMENT | An invalid argument was specified. |
UNAUTHORIZED |
|
FORBIDDEN |
|
INVALID_CONFIG | An invalid setting.
|
INVALID_ID_TOKEN | Failed to verify the ID token. |
EXCEPTION_IN_SUBWINDOW | Problem with subwindow.
|
THINGS_NO_LINKED_DEVICES | No linked device is available. |
BLUETOOTH_SETTING_OFF | Bluetooth is off. |
THINGS_TERMS_NOT_AGREED | LINE Things TOS is not agreed. |
BLUETOOTH_NO_LOCATION_PERMISSION | Location permission is not granted. |
BLUETOOTH_LOCATION_DISABLED | Location setting is off. |
BLUETOOTH_LE_API_UNAVAILABLE | The BLE API for LIFF is not available on this device. |
BLUETOOTH_CONNECT_FAILED | Failed to connect to the device. |
BLUETOOTH_ALREADY_CONNECTED | The device is already connected. |
BLUETOOTH_CONNECTION_LOST | No device is connected. |
BLUETOOTH_UNSUPPORTED_OPERATION | The specified operation is not supported for the specified characteristic. |
BLUETOOTH_SERVICE_NOT_FOUND | The specified service does not exist in the GATT server. |
BLUETOOTH_CHARACTERISTIC_NOT_FOUND | The specified characteristic does not exist in the service. |
UNKNOWN | Unknown error. |
# LIFF SDK properties
# liff.ready
A property holding the Promise
object that resolves when you run liff.init()
for the first time after starting the LIFF app.
If you use liff.ready
, you can execute any process after the completion of liff.init()
.
You can use liff.ready
even before the initialization of the LIFF app by liff.init()
has finished.
Example request
If liff.init()
fails, liff.ready
will not be rejected. Also, it doesn't return a LiffError
object.
# liff.id
The property that holds the LIFF app ID (String
type) passed to liff.init()
.
The value of liff.id
is null
until you run liff.init()
.
Example
# liff.init()
Initializes a LIFF app. You can only call other LIFF SDK methods after calling liff.init()
. The LIFF SDK obtains the access token and ID token of the user from the LINE platform when you initialize the LIFF app.
This property or methods are available even before the liff.init()
method is executed.
You can get the environment in which the LIFF app is running before initializing the LIFF app, or close the LIFF app when the LIFF app initialization fails.
- liff.ready
- liff.getOS()
- liff.getLanguage()
- liff.getVersion()
- liff.getLineVersion()
- liff.isInClient()
- liff.closeWindow()
To use the liff.closeWindow()
method before the initialization of the LIFF app by liff.init()
has finished, your LIFF SDK version must be v2.4.0 or later, and the user's LINE version must be 10.15.0 or later.
- To use the access token obtained by the LIFF SDK, call liff.getAccessToken().
- To use the ID token payload obtained by the LIFF SDK, call liff.getDecodedIDToken().
When users are first redirected to the endpoint URL (primary redirect URL), execute the liff.init()
method.
If executing the liff.init()
method, except for the above timing, INIT_FAILED
is returned and the LIFF app can't be opened.
For more information, see Behaviors from accessing the LIFF URL to opening the LIFF app.
- The
liff.init()
method performs initialization based on information such asliff.state
andaccess_token=xxx
that are given to the URL when opening the LIFF app. To complete the initialization correctly, don't change the URL during server or front-end processing before completingliff.init()
. - The primary redirect URL containing
liff.state
will be redirected to the secondary redirect URL whenliff.init()
is executed. Don't send the URL information to an external logging tool such as Google Analytics, as the primary redirect URL contains sensitive information such as the user's access token. - If you want to redirect with
location.replace()
after executingliff.init()
, design your LIFF app to transition the screen after thePromise
object is resolved.
Example request
# Syntax
liff.init(
config,
successCallback,
errorCallback
)
# Arguments
config
Object
LIFF app configurations
config.liffId
String
LIFF app ID. Can be obtained when you add the LIFF app to your channel. For more information, see Adding a LIFF app to your channel.
The LIFF app ID specified here can be obtained with liff.id
.
successCallback
Function
Callback to return a data object upon successful initialization of the LIFF app.
successCallback is processed at the same time that the Promise
object of the return value is resolved. However, there is no set order to which is processed first.
errorCallback
Function
Callback to return an error object upon failure to initialize the LIFF app.
errorCallback is processed at the same time that the Promise
object of the return value is rejected. However, there is no set order to which is processed first.
# Return value
Returns a Promise
object.
# Error response
When the Promise
is rejected, LiffError
is passed.
# liff.getOS()
Gets the environment in which the user is running the LIFF app.
You can use this method even before the initialization of the LIFF app by liff.init()
has finished.
# Syntax
liff.getOS()
# Arguments
None
# Return value
The environment in which the user is running the LIFF app is returned as a string. Since the return value is based on the name of the OS in the user agent string, the return value is independent of the browser type (LIFF browser, LINE's in-app browser, external browser).
For example, if the user is using iOS, ios
will be returned, regardless of whether the user is using LIFF browser or Safari.
Return value | Description |
---|---|
ios | iOS or iPadOS |
android | Android |
web | Other than the above |
For more information about LIFF app supported operating systems and browsers, see Operating environment.
# liff.getLanguage()
Gets the language settings of the environment in which the LIFF app is running.
You can use this method even before the initialization of the LIFF app by liff.init()
has finished.
# Syntax
liff.getLanguage()
# Arguments
None
# Return value
String containing language settings specified in navigator.language
in the LIFF app's running environment.
# liff.getVersion()
Gets the version of the LIFF SDK.
You can use this method even before the initialization of the LIFF app by liff.init()
has finished.
# Syntax
liff.getVersion()
# Arguments
None
# Return value
The version of the LIFF SDK is returned as a string.
# liff.getLineVersion()
Gets the user's LINE version.
You can use this method even before the initialization of the LIFF app by liff.init()
has finished.
# Syntax
liff.getLineVersion()
# Arguments
None
# Return value
If a user opens the LIFF app using a LIFF browser, the LINE version of the user is returned as a string.
If a user opens the LIFF app using an external browser, null
is returned.
# liff.isInClient()
Determines whether the LIFF app is running in a LIFF browser.
You can use this method even before the initialization of the LIFF app by liff.init()
has finished.
# Syntax
liff.isInClient()
# Arguments
None
# Return value
true
: Running in LIFF browserfalse
: Running in external browser or LINE's in-app browser
# liff.isLoggedIn()
Checks whether the user is logged in.
Example request
# Syntax
liff.isLoggedIn()
# Arguments
None
# Return value
true
: The user is logged infalse
: The user is not logged in
# liff.isApiAvailable()
Checks whether the specified API is available in the environment where you started the LIFF app. Specifically, it verifies whether the current LINE version supports the API and whether the terms and conditions for the API have been accepted.
Example request
# Syntax
liff.isApiAvailable(apiName)
# Arguments
apiName
String
The name of the LIFF client API. You can currently specify these API names:
multipleLiffTransition
is a property which indicates whether another LIFF app can be opened without closing the LIFF app. It is not the name of an API.
# Return value
Returns whether the specified API is available in the current environment.
Return value | Description |
---|---|
true | Available |
false | Unavailable. Returns false in these situations:
|
Always returns true
if the LIFF app is launched in an external browser.
# liff.login()
Performs the LINE Login process (web login) in the LINE's in-app browser or external browser.
You can't use liff.login()
in a LIFF browser, as it is automatically executed when liff.init()
is executed.
The behavior of LINE Login authorization requests within the LIFF browser isn't guaranteed. Also, when opening LIFF apps from an external browser or LINE's in-app browser, make sure to use this method for the login process, not the authorization requests with LINE Login.
Example request
# Syntax
liff.login(loginConfig)
# Arguments
loginConfig
Object
LINE login configurations
loginConfig.redirectUri
String
URL to open in the LIFF app after LINE Login. The default value is the endpoint URL set when you added the LIFF app to the channel. For details on how to set the endpoint URL, see Adding a LIFF app to your channel.
If redirectUri
is specified, it verifies that the Endpoint URL set to the channel of the accessed LIFF URL matches the URL specified in redirectUri
.
For more information on URL matching criteria, see URL validation in the LIFF documentation.
# Return value
None
# liff.logout()
Logs out.
Example request
# Syntax
liff.logout()
# Arguments
None
# Return value
None
# liff.getAccessToken()
Gets the current user's access token.
You can use the access token obtained with this API to send user information from the LIFF app to the server. For more information, see Using user information in LIFF apps and servers in the LIFF documentation.
The access token is valid for 12 hours after being issued. When the user closes the app, the access token is revoked.
- If the user starts the LIFF app in a LIFF browser, the LIFF SDK will get an access token when you call
liff.init()
- If the user starts the LIFF app in an external browser, the LIFF SDK will get an access token when these steps are satisfied:
- You call
liff.login()
. - The user logs in to LINE.
- You call
liff.init()
.
- You call
Example request
# Syntax
liff.getAccessToken()
# Arguments
None
# Return value
Returns the current user's access token as a string.
# liff.getIDToken()
Get the raw ID token of the current user obtained by the LIFF SDK. An ID token is a JSON Web Token (JWT) that contains user information.
You can use the ID token obtained with this API when sending the user information from the LIFF app to the server. For more information, see Using user information in LIFF apps and servers in the LIFF documentation.
When adding a LIFF app to your channel, select the openid
scope. You can't get the ID tokens if you don't select the scope, or the users don't grant permission. The scope selections can be changed in the LIFF tab of the LINE Developers Console even after adding the LIFF app.
- If the user starts the LIFF app in a LIFF browser, the LIFF SDK will get an ID token when you call
liff.init()
- If the user starts the LIFF app in an external browser, the LIFF SDK will get an ID token when these steps are satisfied:
- You call
liff.login()
. - The user logs in to LINE.
- You call
liff.init()
.
- You call
To get the email addresses of users, select the email
scope when adding a LIFF app to your channel. You will get the email addresses once the users grant permission. The scope selections can be changed in the LIFF tab of the LINE Developers Console even after adding the LIFF app.
Example request
# Syntax
liff.getIDToken()
# Argument
None
# Return value
Returns a raw ID token.
# liff.getDecodedIDToken()
Gets the payload of the ID token that's acquired by the LIFF SDK. The payload includes information such as user display name, profile image URL, email address, etc.
Use this API when you want to use the display name of the user in the LIFF app.
Don't send the user information obtained by this API to the server. For more information, see Using user information in LIFF apps and servers in the LIFF documentation.
When adding a LIFF app to your channel, select the openid
scope. You can't get the ID tokens if you don't select the scope, or users don't grant permission. The scope selections can be changed in the LIFF tab of the LINE Developers Console even after adding the LIFF app.
- If the user starts the LIFF app in a LIFF browser, the LIFF SDK will get an ID token when you call
liff.init()
- If the user starts the LIFF app in an external browser, the LIFF SDK will get an ID token when these steps are satisfied:
- You call
liff.login()
. - The user logs in to LINE.
- You call
liff.init()
.
- You call
To get the email addresses of users, select the email
scope when adding a LIFF app to your channel. You will get the email addresses once the users grant permission. The scope selections can be changed in the LIFF tab of the LINE Developers Console even after adding the LIFF app.
Example request
# Syntax
liff.getDecodedIDToken()
# Arguments
None
# Return value
Gets the ID token payload.
For more information on ID token payloads, see the Payload section of Getting profile information and email address based on ID token in the Integrate LINE Login documentation.
Example ID token payload
# liff.getContext()
Gets the screen type (1-on-1 chat, group, room, or external browser) from which the LIFF app is launched. For 1-on-1 chats, groups, and rooms, you also get a unique ID.
Example request
# Syntax
liff.getContext()
# Arguments
None
# Return value
A data object that contains the information necessary to make various API calls.
type
String
The type of screen from where the LIFF app was launched. One of:
utou
: 1-on-1 chatgroup
: Grouproom
: Roomexternal
: External browsernone
: A screen other than a 1-on-1 chat, room, group, or external browser. For example, Wallet tab.
This property isn't returned for LIFF apps after transitioning between LIFF apps.
viewType
String
Size of the LIFF app view, only returned if the type
property is utou
, room
, or group
. One of:
compact
tall
full
For more information, see Adding the LIFF app to a channel.
accessTokenHash
String
First half of the hashed SHA256 value of the access token. Used to validate the access token.
userId
String
User ID. Included when the type
property is utou
, room
, group
, none
or external
. However, null may be returned when type
is external
.
utouId
String
1-on-1 chat ID. Included when the type
property is utou
.
This property isn't returned for LIFF apps after transitioning between LIFF apps.
groupId
String
Group ID. Included when the type
property is group
.
This property isn't returned for LIFF apps after transitioning between LIFF apps.
roomId
String
Room ID. Included when the type
property is room
.
This property isn't returned for LIFF apps after transitioning between LIFF apps.
availability.shareTargetPicker.permission
Boolean
Specifies whether liff.shareTargetPicker()
is available in the environment in which the LIFF app was launched.
true
:liff.shareTargetPicker()
is available.false
:liff.shareTargetPicker()
isn't available.
*To get information about the availability of liff.shareTargetPicker()
, we highly recommend using liff.isApiAvailable('shareTargetPicker') instead.
availability.shareTargetPicker.minVer
String
The minimum LINE version that supports liff.shareTargetPicker().
availability.multipleLiffTransition.permission
Boolean
Displays whether it's possible to transition to another LIFF app without closing the LIFF app within the LIFF browser.
true
: It's possible to open another LIFF app without closing the currently opened LIFF app.false
: It's not possible to open another LIFF app without closing the currently opened LIFF app.
*To get information about the availability of a transition between multiple LIFF apps, we highly recommend using liff.isApiAvailable('multipleLiffTransition') instead.
availability.multipleLiffTransition.minVer
String
The minimum LINE version that supports opening another LIFF app without closing the currently opened LIFF app.
endpointUrl
String
URL of the service endpoint.
permanentLinkPattern
String
How additional information in LIFF URLs is handled. concat
is returned.
For more information, see Opening a LIFF app in the LIFF documentation.
null
is returned in the following cases:
- The LIFF app is launched on an external browser.
- The LIFF app is launched on the LINE's in-app browser and LINE login is used.
Example response (LIFF browser)
Example response (external browser)
# liff.getProfile()
Gets the current user's profile information.
When adding a LIFF app to your channel, select the profile
scope. You can't get user profiles if you don't select the scope, or the user doesn't grant permission. The scope selections can be changed in the LIFF tab of the LINE Developers Console even after adding the LIFF app.
Example request
# Syntax
liff.getProfile()
# Arguments
None
# Return value
Returns a Promise
object.
When the Promise
is resolved, the object containing the user's profile information is passed.
userId
String
User ID
displayName
String
Display name
pictureUrl
String
Image URL. This property is not returned if it has not been set by the user.
statusMessage
String
Status message. This property is not returned if it has not been set by the user.
# Error response
When the Promise
is rejected, LiffError
is passed.
Example user profile information
# liff.getFriendship()
Gets the friendship status between a user and a LINE Official Account.
However, you can only get the friendship status between a user and a LINE Official Account that has been linked to the same LINE Login channel to which your LIFF app has been added. To learn how to link a LINE Official Account to a LINE Login channel, see Add a LINE Official Account as a friend when logged in (bot link) in the LINE Login documentation.
When adding a LIFF app to your channel, select the profile
scope. You can't get the friendship statuses if you don't select the scope, or the users don't grant permission. The scope selections can be changed in the LIFF tab of the LINE Developers Console even after adding the LIFF app.
Example request
# Syntax
liff.getFriendship()
# Arguments
None
# Return value
Returns a Promise
object.
When acquiring the status of friendship, the Promise
is resolved and the information about friendship is passed.
friendFlag
Boolean
true
: The user has added the LINE Official Account as a friend and has not blocked it.- Otherwise,
false
.
# Error response
When the Promise
is rejected, LiffError
is passed.
Example return value
# liff.permanentLink.createUrl()
Gets the permanent link for the current page.
Permanent link format:
https://liff.line.me/{liffId}/{path}?{query}#{URL fragment}
Example request
# Syntax
liff.permanentLink.createUrl()
# Arguments
None
# Return value
Returns the current page's permanent link as a string.
An exception is thrown if the current page URL doesn't start with the URL specified in Endpoint URL.
# liff.permanentLink.setExtraQueryParam()
You can add any query parameter to a permanent link on the current page.
Each time you execute liff.permanentLink.setExtraQueryParam()
, the query parameters added last time are overwritten.
- To delete the added query parameters, execute
liff.permanentLink.setExtraQueryParam("")
. - The added query parameters will be discarded when the user navigates to another page.
Example request
# Syntax
liff.permanentLink.setExtraQueryParam(extraString)
# Arguments
extraString
String
Query parameters to add
# Return value
None
# liff.sendMessages()
Sends messages on behalf of the user to the chat screen where the LIFF app is opened. If the LIFF app is opened on a screen other than the chat screen, messages cannot be sent.
- When adding a LIFF app to your channel, select the
chat_message.write
scope. You can't send a message if you don't select the scope, or the user doesn't grant permission. The scope selections can be changed in the LIFF tab of the LINE Developers Console even after adding the LIFF app. liff.sendMessages()
can't be used with an external browser.
Example request
# Syntax
liff.sendMessages(messages)
# Arguments
messages
Array of objects
Message objects
Max: 5
You can send the following types of Messaging API messages:
- Text message
- Sticker message
- Image message
- Video message
- Audio message
- Location message
- Template message. However, only a URI action can be set as an action.
- Flex Message
When messages are sent to a chat that includes a LINE Official Account, the LINE Platform sends webhook events to the bot server. When image, video, and audio messages are sent using the liff.sendMessages()
method, resulting webhook events contain the contentProvider.type
property whose value is external
. For more information, see Message event in the Messaging API reference.
# Return value
Returns a Promise
object.
- If the message is sent successfully, the
Promise
is resolved. No value is passed. - If you fail to send the message, the
Promise
is rejected andLiffError
is passed.
# liff.openWindow()
Opens the specified URL in the LINE's in-app browser or external browser.
- Use of
liff.openWindow()
in an external browser isn't guaranteed. - If the
url
property doesn't contain a query parameter (?key=value
) but has a URL fragment (#URL-fragment
) in LINE versions earlier than 10.16.0 for iOS, the URL fragment will be set to an invalid value. This table shows an example of the link destination whenhttps://example.com#URL-fragment
is set in theurl
property.
LINE version for iOS | Link destination |
---|---|
Versions prior to 10.16.0 | https://example.com#URL-fragment?is_liff_external_open_window=false |
Version 10.16.0 or later | https://example.com#URL-fragment |
Example request
# Syntax
liff.openWindow(params)
# Arguments
params
Object
Parameter object
params.url
String
URL. Specify the absolute path to the URL.
params.external
Boolean
Whether to open the URL in an external browser. Specify one of the following values: The default value is false
.
true
: Opens the URL in an external browser.false
: Opens the URL in the LINE's in-app browser.
# Return value
None
# liff.shareTargetPicker()
Displays the target picker (screen for selecting a group or friend) and sends the message created by the developer to the selected target. This message appears to your group or friends as if you had sent it.
- To view the target picker, turn on the share target picker in the LINE Developers Console. For more information, see Using share target picker.
- When using an external browser, call
liff.login()
, complete the LINE Login process (web login), then callliff.shareTargetPicker()
.
- Target picker is supported on 10.3.0 or later for both LINE for iOS and LINE for Android.
- Before executing
liff.shareTargetPicker()
, you can confirm that the target picker is available in the environment where the LIFF app is started by executingliff.isApiAvailable()
.
Example request
# Syntax
liff.shareTargetPicker(messages)
# Arguments
messages
Array of objects
Message objects
Max: 5
You can send the following types of Messaging API messages:
- Text message
- Image message
- Video message
- Audio message
- Location message
- Template message. However, only a URI action can be set as an action.
- Flex Message
# Return value (LINE 10.3.0-10.10.0)
Returns a Promise
object.
When the target picker is displayed, the
Promise
resolves.If a problem occurs before the target picker is displayed,
Promise
is rejected andLiffError
is passed. For more information on the LiffError object, see LIFF SDK errors.
- Situations after the target picker is displayed can't be detected, such as when the user doesn't select a destination in the displayed target picker.
- In the callback function where
Promise
has been resolved and rejected, the LIFF app won't work on some devices if the developer usesalert()
.
# Return value (LINE 10.11.0-)
Returns a Promise
object.
If the message is sent correctly,
Promise
is resolved and an object with these properties will be passed.status
String
success
If the user cancels and closes the target picker before sending the message,
Promise
is resolved but the object isn't passed.If a problem occurs before the target picker is displayed,
Promise
is rejected andLiffError
is passed. For more information on the LiffError object, see LIFF SDK errors.
In the callback function where Promise
has been resolved and rejected, the LIFF app won't work on some devices if the developer uses alert()
.
# liff.scanCode()
Starts LINE's QR code reader and gets the string read by the user. To start the QR code reader, grant ScanQR
permission to the LIFF app in the LINE Developers Console.
Due to a technical issue, liff.scanCode()
will be undefined
on LINE 9.19.0 or later for iOS. Check the existence of the function as shown in the sample code before using it.
- Enable ScanQR when adding a LIFF app to your channel. The ScanQR setting can be changed in the LIFF tab of the LINE Developers Console even after adding the LIFF app.
- You cannot use
liff.scanCode()
in an external browser.
Example request
# Syntax
liff.scanCode()
# Arguments
None
# Return value
Returns a Promise
object.
When reading a string by LINE's QR code reader, the Promise
is resolved and the object containing the string read is passed.
value
String
String read by the QR code reader
# liff.closeWindow()
Closes the LIFF app.
To use the liff.closeWindow()
method before the initialization of the LIFF app by liff.init()
has finished, your LIFF SDK version must be v2.4.0 or later, and the user's LINE version must be 10.15.0 or later.
Use of liff.closeWindow()
in an external browser is not guaranteed.
Example request
# Syntax
liff.closeWindow()
# Arguments
None
# Return value
None
# liff.initPlugins()
Enable the plugins.
For example, if you enable the Bluetooth plugin, you can use the client API (liff.bluetooth.*
) provided by the Bluetooth plugin.
Example request
# Syntax
liff.initPlugins(pluginNames)
# Arguments
pluginNames
Array of String
Plugin name. Specify one of the following values:
bluetooth
*The Bluetooth plug-in can only be activated on LINE for Android or versions before 9.19.0 for LINE for iOS. When using LINE 9.19.0 or later for iOS, activation fails and a FORBIDDEN error is returned.
# Return value
Returns a Promise
object.
- If the plugin is enabled successfully, the
Promise
is resolved. - If you fail to enable the plugin, the
Promise
is rejected and the error information is passed.
# liff.bluetooth.getAvailability()
Due to a technical issue, liff.bluetooth.getAvailability()
has been suspended on LINE 9.19.0 or later for iOS.
Check if the Bluetooth plugin can be used. Call this method to check the following conditions:
Bluetooth support for the LIFF app added to your channel is enabled
NoteYou must enable the Bluetooth® Low Energy function of the LIFF app added to your channel to initialize the Bluetooth plugin.
Smartphone has Bluetooth enabled
User has accepted the LINE Things Terms of Use
If using LINE on Android, user has granted permission to use smartphone location information
Enable the Bluetooth plugin by using liff.initPlugins() beforehand.
Example request
# Syntax
liff.bluetooth.getAvailability()
# Arguments
None
# Return value
Returns a Promise
object.
When the Bluetooth plugin is checked for availability, the Promise
is resolved and a Boolean
object indicating whether or not the Bluetooth plugin can be used is passed.
# liff.bluetooth.requestDevice()
Due to a technical issue, liff.bluetooth.requestDevice()
has been suspended on LINE 9.19.0 or later for iOS.
Scans the linked device, and acquires the information.
You can use a filter to restrict the devices that receive the advertisement packets.
Make sure you first enable the Bluetooth plugin with liff.initPlugins().
Example request
# Syntax
liff.bluetooth.requestDevice(options)
# Arguments
options
Object
RequestDeviceOptions
object expressing the filter. Omit to retrieve advertisement packets from all devices.
# Data object
# RequestDeviceOptions object
filters
Array of Object
Array of the LINEBluetoothRequestDeviceFilter
object
# LINEBluetoothRequestDeviceFilter object
deviceId
String
Device ID of the device that receives the advertisement packet
# Return value
Returns a Promise
object.
When scanning linked devices and acquiring the information, the Promise
is resolved and the BluetoothDevice
object indicating information about the devices is passed.
# Data object
# BluetoothDevice object
id
String
Device ID
name
String
device name
gatt
Object
watchingAdvertisements
Boolean
Monitoring status of advertisement packet (*)
Method | Return value | Description |
---|---|---|
watchAdvertisements | Promise <void> | Starts the reception of the advertisement packet. (*) |
unwatchAdvertisements | void | Stops the reception of the advertisement packet. (*) |
addEventListener | void | Registers the event listener. You can register the event listener in advertisementreceived event(*) and gattserverdisconnected event. |
removeEventListener | void | Deletes the already-registered event listener. You can delete the event listener registered in advertisementreceived event(*) and gattserverdisconnected event. |
(*) These functions are implemented on experiment basis. These functions may be changed or stopped without prior notice.
# BluetoothRemoteGATTServer object
To communicate with devices, use the BluetoothRemoteGATTServer
object that expresses the GATT server (Generic Attribute Profile server).
If Promise
is resolved after executing liff.bluetooth.requestDevice()
, then BluetoothRemoteGATTServer
can be accessed from the gatt
property of the BluetoothDevice
object.
device
Object
connected
Boolean
true
if connected. false
if not connected
Method | Return value | Description |
---|---|---|
connect | Promise <BluetoothRemoteGATTService> | Connects with the device. |
disconnect | void | Disconnects from the GATT server of the device. |
getPrimaryService(serviceUUID) | Promise <BluetoothRemoteGATTService> | Acquires the primary service of the GATT server. Specify a 128-bit UUID as a string in the serviceUUID. Note: This method does not verify the UUID. The UUID is verified when the characteristics are read or written, and when a notification is started or stopped. |
# BluetoothRemoteGATTService object
The BluetoothRemoteGATTService
object is used to acquire the characteristics.
device
Object
uuid
String
GATT Service UUID
Method | Return value | Description |
---|---|---|
getCharacteristic(characteristicUUID) | Promise <BluetoothRemoteGATTCharacteristic> | Acquires the characteristics. Specify a 128-bit UUID as a string in the characteristicUUID. Note: This method does not verify the UUID. The UUID is verified when the characteristics are read or written, and when a notification is started or stopped. |
# BluetoothRemoteGATTCharacteristic object
The BluetoothRemoteGATTCharacteristic
object is used to read or write the characteristic of the devices, and also to start or stop a notification.
service
Object
uuid
String
UUID
value
Object
Method | Return value | Description |
---|---|---|
readValue | Promise <DataView (opens new window)> | Reads the value of the characteristic. |
writeValue(value) | Promise <void> | Writes the BufferSource (opens new window) value to the characteristic. |
startNotifications | Promise <BluetoothRemoteGATTCharacteristic> | Starts the notification of characteristic change. |
stopNotifications | Promise <BluetoothRemoteGATTCharacteristic> | Stops the notification of characteristic change. |
addEventListener | void | Registers the event listener. You can register the event listener in characteristicvaluechanged event containing the target property. |
removeEventListener | void | Deletes the already-registered event listener. You can delete the event listener registered in characteristicvaluechanged event. |
readValue()
method, writeValue()
method, startNotifications()
method, and stopNotifications()
method verify the UUID and properties. If a UUID or property that does not exist is specified, an error occurs.
Example request
# Events
# advertisementreceived event
If an advertisement packet is received, the advertisementreceived
event occurs.
The advertisementreceived
event is a function that is implemented on experiment basis. This function may be changed or stopped without prior notice.
device
Object
name
String
device name
rssi
Number
RSSI
manufacturerData
Object
Map<Number, DataView>object. Data in which the Company Identifier Code is mapped to the DataView
object.
# gattserverdisconnected event
If the Bluetooth connection is disconnected due to various reasons, the gattserverdisconnected
event occurs. Be sure to register the event listener.
Example request
# characteristicvaluechanged event
If a characteristic is changed, the characteristicvaluechanged
event occurs.
# liff.bluetooth.referringDevice
Due to a technical issue, liff.bluetooth.referringDevice
has been suspended on LINE 9.19.0 or later for iOS.
When the LIFF app is launched via a device, liff.bluetooth.referringDevice is set to a BluetoothDevice
object that indicates device information.