All Projects → leancloud → Realtime Sdk Flutter

leancloud / Realtime Sdk Flutter

Licence: apache-2.0
LeanCloud Flutter Plugin SDK

Programming Languages

dart
5743 projects

Projects that are alternatives of or similar to Realtime Sdk Flutter

Js Realtime Sdk
LeanCloud Realtime Message JavaScript SDK
Stars: ✭ 193 (+777.27%)
Mutual labels:  leancloud, sdk
Objc Sdk
LeanCloud Objective-C SDK
Stars: ✭ 186 (+745.45%)
Mutual labels:  leancloud, sdk
Swift Sdk
LeanCloud Swift SDK
Stars: ✭ 110 (+400%)
Mutual labels:  leancloud, sdk
Javascript Sdk
LeanCloud JavaScript SDK
Stars: ✭ 307 (+1295.45%)
Mutual labels:  leancloud, sdk
Pesdk Ios Examples
A fully customizable photo editor for your app.
Stars: ✭ 837 (+3704.55%)
Mutual labels:  sdk
Chat Sdk Ios
Chat SDK iOS - Open Source Mobile Messenger
Stars: ✭ 813 (+3595.45%)
Mutual labels:  sdk
Gatewayworker
Distributed realtime messaging framework based on workerman.
Stars: ✭ 801 (+3540.91%)
Mutual labels:  realtime-messaging
Sdk Js
Tanker client-side encryption SDK for JavaScript
Stars: ✭ 786 (+3472.73%)
Mutual labels:  sdk
Win Php Sdk Builder
build a php-sdk environment on Win
Stars: ✭ 19 (-13.64%)
Mutual labels:  sdk
Centrifuge
Cross-platform runtime mod loader and API for any Unity-based game. Supports Unity 5 and up!
Stars: ✭ 18 (-18.18%)
Mutual labels:  sdk
Sfml
Simple and Fast Multimedia Library
Stars: ✭ 7,316 (+33154.55%)
Mutual labels:  sdk
Miniapp
微信小程序服务端 SDK (for Golang)
Stars: ✭ 815 (+3604.55%)
Mutual labels:  sdk
Iran Onesignal
Avoid onesignal sanctions for IRAN. (Updated to v2.9.4)
Stars: ✭ 17 (-22.73%)
Mutual labels:  sdk
Parse Php Sdk
The Parse PHP SDK.
Stars: ✭ 810 (+3581.82%)
Mutual labels:  sdk
Circuit Sdk
JavaScript and Node.js SDK for Circuit
Stars: ✭ 18 (-18.18%)
Mutual labels:  sdk
Botframework Sdk
Bot Framework provides the most comprehensive experience for building conversation applications.
Stars: ✭ 6,673 (+30231.82%)
Mutual labels:  sdk
Sdk
The Dart SDK, including the VM, dart2js, core libraries, and more.
Stars: ✭ 7,539 (+34168.18%)
Mutual labels:  sdk
Azure Kinect Sensor Sdk
A cross platform (Linux and Windows) user mode SDK to read data from your Azure Kinect device.
Stars: ✭ 889 (+3940.91%)
Mutual labels:  sdk
Themoviedb
A node.js module with support for both callbacks and promises to provide access to the TMDb API
Stars: ✭ 5 (-77.27%)
Mutual labels:  sdk
Midiconstants
An unofficial MIDI SDK
Stars: ✭ 5 (-77.27%)
Mutual labels:  sdk

leancloud_official_plugin

An official flutter plugin for LeanCloud real-time message service based on LeanCloud-Swift-SDK and LeanCloud-Java-SDK.

Flutter Getting Started

This project is a starting point for a Flutter plug-in package, a specialized package that includes platform-specific implementation code for Android and iOS.

For help getting started with Flutter, view online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

Usage

Adding dependency

  1. Following this document to add leancloud_official_plugin to your app, like this:

    dependencies:
      leancloud_official_plugin: '>=x.y.z <(x+1).0.0'    # Recommend using up-to-next-major policy.
    
  2. Using Gradle and CocoaPods to add platform-specific dependencies.

    • Using CocoaPods in terminal
      • do $ cd ios/
      • then $ pod update or $ pod install --repo-update
    • Gradle

Initialization

  1. import package:leancloud_official_plugin/leancloud_plugin.dart in lib/main.dart of your project, like this:

    import 'package:leancloud_official_plugin/leancloud_plugin.dart';
    
  2. import cn.leancloud.AVOSCloud, cn.leancloud.AVLogger and cn.leancloud.im.AVIMOptions in YourApplication.java of your project, then set up ID, Key and URL, like this:

    import io.flutter.app.FlutterApplication;
    import cn.leancloud.AVOSCloud;
    import cn.leancloud.AVLogger;
    import cn.leancloud.im.AVIMOptions;
    
    public class YourApplication extends FlutterApplication {
      @Override
      public void onCreate() {
        super.onCreate();
        AVIMOptions.getGlobalOptions().setUnreadNotificationEnabled(true);
        AVOSCloud.setLogLevel(AVLogger.Level.DEBUG);
        AVOSCloud.initialize(this, YOUR_LC_APP_ID, YOUR_LC_APP_KEY, YOUR_LC_SERVER_URL);
      }
    }
    
  3. import LeanCloud in AppDelegate.swift of your project, then set up ID, Key and URL, like this:

    import Flutter
    import LeanCloud
    
    @UIApplicationMain
    @objc class AppDelegate: FlutterAppDelegate {
        override func application(
            _ application: UIApplication,
            didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
        ) -> Bool {
            do {
                LCApplication.logLevel = .all
                try LCApplication.default.set(
                    id: YOUR_LC_APP_ID,
                    key: YOUR_LC_APP_KEY,
                    serverURL: YOUR_LC_SERVER_URL)
                GeneratedPluginRegistrant.register(with: self)
                return super.application(application, didFinishLaunchingWithOptions: launchOptions)
            } catch {
                fatalError("\(error)")
            }
        }
    }
    

Push setup (optional)

Due to different push service in iOS and Android, the setup-code should be wrote in native platform. it's optional, so if you no need of push service, you can ignore this section.

  • iOS

    import Flutter
    import LeanCloud
    import UserNotifications
    
    @UIApplicationMain
    @objc class AppDelegate: FlutterAppDelegate {
        override func application(
            _ application: UIApplication,
            didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
        ) -> Bool {
            do {
                LCApplication.logLevel = .all
                try LCApplication.default.set(
                    id: YOUR_LC_APP_ID,
                    key: YOUR_LC_APP_KEY,
                    serverURL: YOUR_LC_SERVER_URL)
                GeneratedPluginRegistrant.register(with: self)
                /*
                register APNs to access token, like this:
                */ 
                UNUserNotificationCenter.current().getNotificationSettings { (settings) in
                    switch settings.authorizationStatus {
                    case .authorized:
                        DispatchQueue.main.async {
                            UIApplication.shared.registerForRemoteNotifications()
                        }
                    case .notDetermined:
                        UNUserNotificationCenter.current().requestAuthorization(options: [.badge, .alert, .sound]) { (granted, error) in
                            if granted {
                                DispatchQueue.main.async {
                                    UIApplication.shared.registerForRemoteNotifications()
                                }
                            }
                        }
                    default:
                        break
                    }
                }
                return super.application(application, didFinishLaunchingWithOptions: launchOptions)
            } catch {
                fatalError("\(error)")
            }
        }
        
        override func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
            super.application(application, didRegisterForRemoteNotificationsWithDeviceToken: deviceToken)
            /*
            set APNs deviceToken and Team ID.
            */
            LCApplication.default.currentInstallation.set(
                deviceToken: deviceToken,
                apnsTeamId: YOUR_APNS_TEAM_ID)
            /*
            save to LeanCloud.
            */
            LCApplication.default.currentInstallation.save { (result) in
                switch result {
                case .success:
                    break
                case .failure(error: let error):
                    print(error)
                }
            }
        }
    
        override func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
            super.application(application, didFailToRegisterForRemoteNotificationsWithError: error)
            print(error)
        }
    }
    
  • Android

    reference

Sample Code

After initialization, you can write some sample code and run it to check whether initializing success, like this:

Open

// new an IM client
Client client = Client(id: CLIENT_ID);
// open it
await client.open();

Query Conversations

// the ID of the conversation instance list
List<String> objectIDs = [...];
// new query from an opened client
ConversationQuery query = client.conversationQuery();
// set query condition
query.whereContainedIn(
  'objectId',
  objectIDs,
);
query.limit = objectIDs.length;
// do the query
List<Conversation> conversations = await query.find();
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].