Line SDK wrapper for React Native 🚀
This library includes:
Requirements
- React native
>=0.61.1
- iOS 10.0 or later as the development target
- Android
minSdkVersion
set to 17 or higher
- LINE developer account with a channel created.
Installation
First, install the npm package with yarn. Autolink is automatic.
yarn add @yplabs-ltd/react-native-line
iOS Setup
Using Objective-C
Inside your AppDelegate.m
, setup the line sdk by passing the channel id obtained.
- Add
platform :ios, '10.0'
in Podfile
line:1
- Modify your info.plist like it says here Configuring the Info.plist file
- Change your
AppDelegate.m
to match the following:
@import RNLine;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[LineLogin setupWithChannelID:@"YOUR_CHANNEL_ID" universalLinkURL:nil];
}
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
{
return [LineLogin application:app open:url options:options];
}
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler
{
BOOL handledLine = [LineLogin application:application continue:userActivity restorationHandler:restorationHandler];
return handledLine;
}
Using Swift
import LineLogin
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
LineLogin.setup(channelID: "YOUR_CHANNEL_ID", universalLinkURL: nil)
return true
}
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
return LineLogin.application(app, open: url, options: options)
}
Don't forget to add application
function, as line's instructions indicate.
Android Setup
- Follow all the configuration steps in Line's Android integration guide
- Add the string
line_channel_id
to your strings file with the the channel id that you have on your line console.
<string name="line_channel_id" translatable="false">Your channel id here</string>
- Add
minSdkVersion = 17
in android/build.gradle
- Add LineSDK as a dependency in
android/build.gradle
android {
// Enable Java 1.8 support.
compileOptions { // <- add this block if didn't setup
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
...
dependencies {
...
implementation 'com.linecorp.linesdk:linesdk:5.7.0' // <- add this line
}
}
- In your manifest add
xmlns:tools="http://schemas.android.com/tools"
in your manifest
tag and also tools:replace="android:allowBackup"
in your application
tag
API
First, require the LineLogin
module:
import LineLogin from '@yplabs-ltd/react-native-line'
Then, you can start using all the functions that are available:
login(args?: LoginArguments): Promise<LoginResult> | Starts the login flow of Line's SDK (Opens the apps if it's installed and defaults to the browser otherwise). It accepts the same argumements as the LineSDK, in an object { key: value } , defaults the same way as LineSDK too. |
getCurrentAccessToken(): Promise<AccessToken> | Returns the current access token for the currently logged in user. |
getProfile(): Promise<UserProfile> | Returns the profile of the currently logged in user. |
logout(): Promise<void> | Logs out the currently logged in user. |
refreshToken(): Promise<AccessToken> | Refreshes the access token and returns it. |
verifyAccessToken(): Promise<AccessTokenVerifyResult> | Verifies the access token and returns it. |
getBotFriendshipStatus(): Promise<BotFriendshipStatus> | Gets bot friendship status if configured. |
Return values
The following objects are returned on the methods described above:
{
userID: String
displayName: string
pictureURL?: string
statusMessage?: string
}
{
access_token: String
expires_in: String
id_token?: String
}
{
client_id: String
expires_in: String
scope: String
}
{
accessToken: AccessToken
scope: String
userProfile?: UserProfile
friendshipStatusChanged?: boolean
IDTokenNonce?: String
}
{
friendFlag: boolean
}
Arguments
{
scopes?: LoginPermission[]
onlyWebLogin?: boolean
botPrompt?: BotPrompt
}
{
EMAIL = 'email',
OPEN_ID = 'openid',
PROFILE = 'profile',
}
{
aggressive = 'aggressive',
normal = 'normal',
}
Usage
- Login with default values:
try {
...
const loginResult = await Line.login()
...
} catch (error) {
...
}
try {
...
const loginResult = await Line.login({
scopes: ['email', 'profile'],
botPrompt: 'normal'
})
...
} catch (error) {
...
}
try {
...
const profile = await Line.getProfile()
...
} catch (error) {
...
}
try {
...
await Line.logout()
...
} catch (error) {
...
}
Example
If you want to see @yplabs-ltd/react-native-line
in action, just move into the example folder and run yarn ios
/yarn android
. By seeing its source code, you will have a better understanding of the library usage.