4.1.0 • Published 10 months ago
@xmartlabs/react-native-line v4.1.0
Line SDK wrapper for React Native 🚀
- LINE SDK v5 for iOS, wrapped with Swift.
- LINE SDK v5 for Android, wrapped with Kotlin.
Requirements
- Android
minSdkVersionneeds to be at least version24. - iOS
deploymentTargetneeds to be at least version15.1. - LINE developer account with a channel created.
Installation
With Expo
Install the JavaScript side with:
npx expo install @xmartlabs/react-native-lineAdd the plugin
expo-build-propertiesto yourapp.json:"plugins": [ [ "expo-build-properties", { "ios": { "useFrameworks": "static" // This is required } } ], "@xmartlabs/react-native-line" ]
With react-native-cli
Install library:
npm install @xmartlabs/react-native-line # --- or --- yarn add @xmartlabs/react-native-lineLink native code:
cd ios && pod installChange your
AppDelegate.mto match the following:#import "RNLine-Swift.h" ... - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options { return [LineLogin application:application open:url options:options]; }Insert the following snippet in your
Info.plistto match the LINE documentation:<key>CFBundleURLTypes</key> <array> <dict> <key>CFBundleTypeRole</key> <string>Editor</string> <key>CFBundleURLSchemes</key> <array> <string>line3rdp.$(PRODUCT_BUNDLE_IDENTIFIER)</string> </array> </dict> </array> <key>LSApplicationQueriesSchemes</key> <array> <string>lineauth2</string> </array>
Usage
Import the
LineLoginmodule:import LineLogin from '@xmartlabs/react-native-line'Initialize the module with the
setupmethod:useEffect(() => { LineLogin.setup({ channelId: 'YOUR_CHANNEL_ID' }) }, [])Login with the
loginmethod:LineLogin.login()
API
| Function | Description |
|---|---|
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. |
Example
If you want to see @xmartlabs/react-native-line in action, just move into the example folder and run npm install and then npm run ios/npm run android. By seeing its source code, you will have a better understanding of the library usage.
License
@xmartlabs/react-native-line is available under the MIT license. See the LICENCE file for more info.
