Skip to content

kota113/react-native-line

Β 
Β 

Repository files navigation

React Native Line

npm version PRs welcome

Line SDK wrapper for React Native πŸš€

Requirements

  • Android minSdkVersion needs to be at least version 24.
  • iOS deploymentTarget needs to be at least version 15.1.
  • LINE developer account needs to be created and also a channel.

Important

@xmartlabs/react-native-line v5 is now a TurboModule and requires the new architecture to be enabled.

  • If you want to use @xmartlabs/react-native-line v5, you will need to enable the new architecture in your app (see how to enable the new architecture for apps).
  • If you cannot enable the new architecture yet, downgrade to @xmartlabs/react-native-line v4 for now.

Installation

With Expo

  1. Install the JavaScript side with:

    npx expo install @xmartlabs/react-native-line
  2. Add the plugins expo-build-properties and @xmartlabs/react-native-line to your app.json:

    "plugins": [ [ "expo-build-properties", { "ios": { "useFrameworks": "static" } } ], "@xmartlabs/react-native-line" ]

With react-native-cli

  1. Install library:

    npm install @xmartlabs/react-native-line # --- or --- yarn add @xmartlabs/react-native-line
  2. Link iOS native code:

    cd ios && pod install
  3. Change your AppDelegate to match the following:

    With Objective-C

    @xmartlabs/react-native-line v4
    #import "RNLine-Swift.h" ... - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options { return [LineLogin application:application open:url options:options]; }
    @xmartlabs/react-native-line v5
    #import "react_native_line-Swift.h" ... - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options { return [LineLogin application:application open:url options:options]; }

    With Swift

    @xmartlabs/react-native-line v4
    import RNLine ... override func application(_ application: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool { return LineLogin.application(application, open: url, options: options) }
    @xmartlabs/react-native-line v5
    import react_native_line ... override func application(_ application: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool { return LineLogin.application(application, open: url, options: options) }
  4. Insert the following snippet in your Info.plist just before the last </dict> tag:

    <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>

Migration guide

You can find the migration guide in the linked document.

Usage

  1. Import the Line module:

    import Line from '@xmartlabs/react-native-line'
  2. Initialize the module with the setup method:

    useEffect(() => { Line.setup({ channelId: 'YOUR_CHANNEL_ID' }) }, [])
  3. Log in with the login method:

    Line.login({})

API

Method Description
login(params: LoginParams): 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 access token of the current user.
getProfile(): Promise<UserProfile> Returns the current user profile information.
logout(): Promise<void> Revokes the access token of the current user.
refreshAccessToken(): Promise<AccessToken> Refreshes the access token of the current user.
setup(params: SetupParams): Promise<void> Initializes the Line SDK.
verifyAccessToken(): Promise<VerifyResult> Checks whether the access token of the current user is valid.
getFriendshipStatus(): Promise<FriendshipStatus> Gets the friendship status between the LINE Official Account (which is linked to the current channel) and the user 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.

Xmartlabs Logo

Created with ❀️ by Xmartlabs

About

Line SDK wrapper for React Native πŸš€

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 43.7%
  • Kotlin 22.8%
  • JavaScript 15.5%
  • Swift 13.4%
  • Objective-C++ 3.1%
  • Ruby 1.3%
  • Objective-C 0.2%