Coder Social home page Coder Social logo

phithu / rn-zalo Goto Github PK

View Code? Open in Web Editor NEW
34.0 1.0 19.0 77.59 MB

A React Native Module for Zalo SDK

Home Page: https://www.npmjs.com/package/rn-zalo

Java 68.89% JavaScript 5.67% Objective-C 20.47% Ruby 4.96%
react-native react-native-zalo rn-zalo zalo

rn-zalo's Introduction

React Native Zalo

npm version npm MIT Platform - Android and iOS

Android iOS

Installation

yarn add rn-zalo or npm i rn-zalo --save

Zalo SDK Documents

Setup (Mandatory)

iOS

1. Install pod: cd ios && pod install
2. Add url type Main target setting -> info -> URL types -> click +

identifier = “zalo”, URL Schemes = “zalo-<YOUR_APP_ID>”

3. Open AppDelegate.m
#import <ZaloSDK/ZaloSDK.h>
- (BOOL)application:(UIApplication *)application
 didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    ...
    [[ZaloSDK sharedInstance] initializeWithAppId:@"<YOUR_APP_ID>"];
    return YES;
}
 
- (BOOL)application:(UIApplication *)application openURL:(nonnull NSURL *)url options:(nonnull NSDictionary<NSString *,id> *)options {
  return [[ZDKApplicationDelegate sharedInstance] application:application openURL:url options:options];
}
4. Clear and Run your project

Android

1. Open up android/app/src/main/java/[...]/MainApplication.java
  • Add import com.zing.zalo.zalosdk.oauth.ZaloSDKApplication; to the imports
  • Add ZaloSDKApplication.wrap(this) on "onCreate" function
2. Open up android/app/src/main/java/[...]/MainActivity.java
import android.content.Intent;
import com.zing.zalo.zalosdk.oauth.ZaloSDK;
import com.facebook.react.ReactActivity;

public class MainActivity extends ReactActivity {
   ...
    
   @Override
   public void onActivityResult(int requestCode, int resultCode, Intent data) {
       super.onActivityResult(requestCode, resultCode, data);
       ZaloSDK.Instance.onActivityResult(this, requestCode, resultCode, data);
   }
}
3. Insert the following lines inside the dependencies block in android/app/build.gradle
implementation "com.zing.zalo.zalosdk:core:+"
implementation "com.zing.zalo.zalosdk:auth:+"
implementation "com.zing.zalo.zalosdk:openapi:+"
4. Add appId to android/app/src/main/res/values/strings.xml
<resources>
    <string name="app_name">App Name</string>
    <string name="appID"><YOUR_APP_ID></string>
</res>
5. Add code bellow to android/app/src/main/res/AndroidManifest.xml
 <application
        ...
        <meta-data
            android:name="com.zing.zalo.zalosdk.appID"
            android:value="@string/appID" />

        <activity
            android:name="com.zing.zalo.zalosdk.oauth.BrowserLoginActivity">
        <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="zalo-[appid]" />
    <!-- Lưu ý: thay [appid] bằng id của ứng dụng lấy trên trang developers --!>
    </intent-filter>
        </activity>
    </application>
6. Open proguard-rules.pro file add code below
-keep class com.zing.zalo.**{ *; }
-keep enum com.zing.zalo.**{ *; }
-keep interface com.zing.zalo.**{ *; }

Usage

import {
  StyleSheet,
  View,
  TouchableOpacity,
  Image,
  Text,
} from 'react-native';
import React from 'react';
import RNZalo from 'rn-zalo';

export default class App extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      data: null,
    };
  }

  login = async () => {
    try {
      const data = await RNZalo.login();
      this.setState({ data });
    } catch (e) {
      console.log('e', e);
    }

  };

  logout = () => {
    RNZalo.logout();
  };

  renderUser() {
    if (!this.state.data) {
      return null;
    }
    const { birthday, gender, id, picture, name } = this.state.data.user;
    return (
      <View style={styles.userInfoContainer}>
        <Text style={{ fontSize: 18, fontWeight: 'bold' }}>Name: {name}</Text>
        <Text>Id: {id}</Text>
        <Text>Birthday: {birthday}</Text>
        <Text>Gender: {gender}</Text>
        <Image
          style={{ width: 100, height: 100, borderRadius: 50, marginTop: 20 }}
          source={{ uri: picture.data.url }}
        />
      </View>
    );
  }

  render() {
    return (
      <View style={styles.container}>
        <View style={{ marginTop: 30 }}>
          <TouchableOpacity style={styles.buttonStyle} onPress={this.login}>
            <Text style={{ color: '#fff', fontSize: 18 }}>Login</Text>
          </TouchableOpacity>

          <TouchableOpacity style={styles.buttonStyle} onPress={this.logout}>
            <Text style={{ color: '#fff', fontSize: 18 }}>Logout</Text>
          </TouchableOpacity>
        </View>
        {this.renderUser()}
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#F5FCFF',
  },
  userInfoContainer: {
    flexGrow: 1,
    flexShrink: 1,
    alignItems: 'center',
  },
  buttonStyle: {
    alignSelf: 'center',
    paddingVertical: 10,
    paddingHorizontal: 20,
    backgroundColor: 'blue',
    flexDirection: 'row',
    alignItems: 'center',
    borderRadius: 5,
    marginVertical: 10,
  },
});

Issues:

  1. If you see the warning RCTBridge required dispatch_sync to load RCTDevLoadingView. This may lead to deadlocks => Follow this link facebook/react-native#16376 (comment) to resolve it

rn-zalo's People

Contributors

doko-demo-doa avatar phithu avatar phithuxyz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

rn-zalo's Issues

[iOS] Calling RNZalo.login() cause crashed on [email protected]

Hi,
I installed rn-zalo and used fully auto-linking on [email protected]
iOS build process was ok
=> Then navigated to login screen, pressed a button to callRNZalo.login() ==> app crahed, this is the debug content:

[ZOZaloAuthenticator googleClientIdInPlist]: unrecognized selector sent to instance 0x280f234e0
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ZOZaloAuthenticator googleClientIdInPlist]: unrecognized selector sent to instance 0x280f234e0'

Do you have another workaround

Update: Reproduction steps:

  1. Init new rn project, the react-native version should be 0.61.5:
react-native init testZalo
yarn add rn-zalo
pod install --project-directory=ios
react-native run-ios

Some more configuration

5. Add URL Type Main target setting -> info -> URL types -> click +
identifier = “zalo”, URL Schemes = “zalo-<YOUR_APP_ID>”

6. Open AppDelegate.m
...
#import <ZaloSDK/ZaloSDK.h>
- (BOOL)application:(UIApplication *)application
 didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    ...
    [[ZaloSDK sharedInstance] initializeWithAppId:@"<YOUR_APP_ID>"];
    return YES;
}
...  

- (BOOL)application:(UIApplication *)application openURL:(nonnull NSURL *)url options:(nonnull NSDictionary<NSString *,id> *)options {
  return [[ZDKApplicationDelegate sharedInstance] application:application openURL:url options:options];
}

7. Clear and Run your project

Or you can use /rn-zalo/demo project

  1. Run RNZalo.login() from JS ==> Worked
  2. Install react-navigation:
yarn add react-native-reanimated react-native-gesture-handler react-native-screens react-native-safe-area-context @react-native-community/masked-view
pod install --project-directory=ios
react-native run-ios
  1. Run RNZalo.login() from JS ==> Crashed

Archive Error: bitcode bundle could not be generated

I got the error when archiving the project, got the same error on 3 projects:

Minimal reproduction steps:

  • clone this https://github.com/phithu/rn-zalo
  • cd demo/ios, install node module and pod
  • Product > Run ==> App can be installed and run successfully
  • Product > Archive ==> got the error:
ld: bitcode bundle could not be generated because '/Users/luatnd/Downloads/rn-zalo-master/demo/ios/Pods/ZaloSDK/ZaloSDK/Frameworks/ZaloSDK.framework/ZaloSDK(Pods-ZaloSDK-dummy.o)' was built without full bitcode. All object files and libraries for bitcode must be generated from Xcode Archive or Install build file '/Users/luatnd/Downloads/rn-zalo-master/demo/ios/Pods/ZaloSDK/ZaloSDK/Frameworks/ZaloSDK.framework/ZaloSDK' for architecture arm64

Library for android

Error of me: Error: Không thể đăng nhập Zalo and when i click login button Zalo app show but screen show grant access and don't login zalo?.
Pls fix for me or give me suggestions to fix this

Login faild

when i console.log response data:

{"user": {"error": -1013, "error_description": "The parameter pckg_name and sign_key are required.", "error_name": "Invalid Parameter", "error_reason": ""}}

how to fix it?

Can't login with iOS

When i was login, i had issue: "The operation couldn’t be completed. (Zalo Oauth error -1012.)"
Please help me!!!

Lỗi không getProfile được

sau khi em chạy RNZalo.login(); thì nó log thế này. mong anh giúp đỡ

{"oauthCode": "8ZupBflXbX5s47Xi-u6sO3j8O1AykASPSK4M5hRbunmt3LOHx_-pRMKPRaYQuRq_7n1uCzVStYmsHHGXjgUZB7v2V5dtqfjwFX9n7elRjX54D0aiZQx08XHtH2gqauXuIbGZ8kl_w5Hp3Z1QgkVwDYCwVZ2wjS0i4nzv4yRGsXyOAGLx_8oNA6njNqB_e8D7PZTFBiVSn59TLm5GfAV541etS66klwufO1PoNzZyyqCqU2OEXlxc8HZGyJgE5WS4OwhIU8G2BaKSYUikrmWICKZwYqIcRqL9EE2Q9v1XIm4oxUKPtsav0_e6Bn71dSyJ", "user": {"error": -1013, "error_description": "Invalid Parameter", "error_name": "Invalid Parameter", "error_reason": ""}}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.