封装的一个腾讯云im,以便于flutter开发者可以方便继承im到自己的应用中
开发者需要到腾讯云上申请一个appid,申请地址
申请成功之后,平台会分配一个appid给到开发者。
1、sig的获取,sig一般就是开发者自己的后台开发同学提供,可以参考腾讯云文档实现sig申请。
2、都准备ok了,就可以登录imsdk了。
登录代码参考这里:
Future<void> login() async {
try {
// var result = await _dim.imLogin(1400117017, "rq3",
// "eJxlz11PwjAUgOH7-YpmtxjTj32AdwuCMIcGJkq9WWbXlkbsSul0avjvhkniEs-t856cnG8PAOA-ZPllyVjdaFe4T8N9cAV86F-8oTGqKkpXEFv9Q94aZXlRCsdthygMQwxhv1EV104JdS7snvTwUL0W3YXf7QBChGKI4n6iZIeLCR3Pl9dGrMUwj1iyqvSNXNMmmyU5HQ6mVjwumjs5truYbkcbTeR8m6RCRLssu0*pfVrepvmgbdhzFr1MP7gLZ-ir3qxkPGlZsB-1Tjr1xs-vBBBHJA5wT9*5PahadwGGKESYwNP43tH7ARZeXFI_");
var result = await _dim.imLogin(1400117017, "rq2",
"eJxlz01Pg0AQgOE7v4Ls2ejMwnaxSQ9Sq60W09o2QS*ElKGsHxS2SxGM-92ITSRxrs87mcynZds2W89X5-F2u69yE5mmIGYPbQbs7A*LQiVRbCJHJ-*QPgqlKYpTQ7pDFEJwgH6jEsqNStWp0CXv4SF5jboLv9suAKIElP1E7ToMJsvx7HpuKGhhJ1J3WU-Tl0E1fp6oMPPC9SNlOHiqFhftBmdhvLhSvi-L*yn4spG5vinfNGUplu2x8bmHCbmeaaugvn248zb1aNQ7adQ7nd5xgaO8dLyeHkkf1D7vAg4okDvwM8z6sr4BAlVcKw__");
print(result);
} on PlatformException {
print("登录 失败");
}
}
ios端配置:
因为git上传文件必须要小于100m的限制,所以云im有些framework上传不了,因此需要开发者自己到[这里下载](http://dldir1.qq.com/hudongzhibo/im/IM_iOS_SDK_3.3.2.zip)。
下载好了zip包之后,把里面的这些framework copy到 `/Users/xxx/.pub-cache/hosted/pub.dartlang.org/dim-0.x.x/ios`
目录下(注意,运行fetch_libs.sh获取所有的framework).
随后到你的工程的ios文件夹中执行 `pod install`
然后就可以跑起来了。
如果不可以跑起来,报了这样的错误。
Undefined symbols for architecture x86_64: "operator new[](unsigned long, std::nothrow_t const&)", referenced from: openbdh::BdhUpTransaction::initSegmentList() in ImSDK(bdhUpTransaction.o) openbdh::BdhUpTransaction::getData(openbdh::DataTransInfo*) in ImSDK(bdhUpTransaction.o) "std::__1::__throw_system_error(int, char const*)", referenced from: std::__1::unique_lockstd::__1::mutex::unlock() in ImSDK(task_queue.o) "_uncompress", referenced from:
这说明你本地的一些库没有引用,用xcode打开你的ios工程,然后[参考这里](https://cloud.tencent.com/document/product/269/9147)
这里如何集成IMSDK写的很清楚,需要依赖系统的那些库。
注意:
1、引入的时候搜索你会发现.dylib现在变为了.tbd了。还有就是IOS模拟器跑不了,腾讯云没有提供X86的framework。
2、注意不要引入IMUGCExt.framework,TXRTMPSDK.framework。
3、注意,当你升级dim之后,cache对应的版本中没有这些库了,因此要在copy一份过去,可以直接从你之前的版本中copy,在到ios工程下执行`pod install`。
## 已有的功能
1、登录
2、登出
3、获取会话列表
4、删除一个会话
5、获取会话消息
6、发送图片消息
7、发送文本消息
8、发送地理位置消息
获取用户个人资料
简化dim的使用,android端不在需要在AndroidManifests.xml文件中配置service等内容,全部交给插件处理。
example/lib/main.dart
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:dim/dim.dart';
void main() => runApp(new MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => new _MyAppState();
}
class _MyAppState extends State<MyApp> {
Dim _dim = new Dim();
String _platformVersion = 'Unknown';
StreamSubscription<dynamic> _messageStreamSubscription;
@override
void initState() {
super.initState();
initPlatformState();
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
String platformVersion;
// Platform messages may fail, so we use a try/catch PlatformException.
try {
platformVersion = await _dim.platformVersion;
} on PlatformException {
platformVersion = 'Failed to get platform version.';
}
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;
if (_messageStreamSubscription == null) {
_messageStreamSubscription = _dim.onMessage.listen((dynamic onData) {
print("我监听到数据了$onData");
});
}
setState(() {
_platformVersion = platformVersion;
});
}
@override
void dispose() {
// TODO: implement dispose
super.dispose();
//flutter 这里应该页面退出栈会调用,但是如果这个是根页面,日志是打不出来的。
canCelListener();
}
@override
Widget build(BuildContext context) {
return new MaterialApp(
home: new Scaffold(
appBar: new AppBar(
title: const Text('Plugin example app'),
),
body: new Center(
child: new Column(
children: <Widget>[
new Text('Running on: $_platformVersion\n'),
RaisedButton(
onPressed: () {
login();
},
child: Text('登录imsdk'),
),
RaisedButton(
onPressed: () {
logout();
},
child: Text('登出imsdk'),
),
RaisedButton(
onPressed: () {
postData();
},
child: Text('测试发送数据'),
),
RaisedButton(
onPressed: () {
canCelListener();
},
child: Text('取消监听'),
),
RaisedButton(
onPressed: () {
sendTextMsg();
},
child: Text('发送文本消息'),
),
RaisedButton(
onPressed: () {
sendImageMsg();
},
child: Text('发送图片消息'),
),
RaisedButton(
onPressed: () {
sendLocationMsg();
},
child: Text('发送位置消息'),
),
RaisedButton(
onPressed: () {
getMessages();
},
child: Text('拿到历史消息'),
),
RaisedButton(
onPressed: () {
getUserInfo();
},
child: Text('获取个人资料'),
),
],
),
),
),
);
}
Future<void> postData() async {
try {
var result = await _dim.postDataTest();
print(result);
} on PlatformException {
print("listen 失败");
}
}
// Future<void> login() async {
// try {
// var result = await _dim.imLogin(1400119955, "18681446372", "eJxlz11PwjAUgOH7-YpmtxjTj32AdwuCMIcGJkq9WWbXlkbsSul0avjvhkniEs-t856cnG8PAOA-ZPllyVjdaFe4T8N9cAV86F-8oTGqKkpXEFv9Q94aZXlRCsdthygMQwxhv1EV104JdS7snvTwUL0W3YXf7QBChGKI4n6iZIeLCR3Pl9dGrMUwj1iyqvSNXNMmmyU5HQ6mVjwumjs5truYbkcbTeR8m6RCRLssu0*pfVrepvmgbdhzFr1MP7gLZ-ir3qxkPGlZsB-1Tjr1xs-vBBBHJA5wT9*5PahadwGGKESYwNP43tH7ARZeXFI_");
//// var result = await _dim.postDataTest();
// print(result);
// } on PlatformException {
// print("登录 失败");
// }
// }
Future<void> sendTextMsg() async {
try {
var result = await _dim.sendTextMessages("rq2", "haahah");
print(result);
} on PlatformException {
print("发送消息失败");
}
}
Future<void> sendImageMsg() async {
try {
var result = await _dim.sendImageMessages("rq2", "tyyhuiijkoi.png");
print(result);
} on PlatformException {
print("发送图片消息失败");
}
}
Future<void> sendLocationMsg() async {
try {
var result =
await _dim.sendLocationMessages("rq2", 113.93, 22.54, "腾讯大厦");
print(result);
} on PlatformException {
print("发送位置消息失败");
}
}
Future<void> login() async {
try {
// var result = await _dim.imLogin(1400117017, "rq3",
// "eJxlz11PwjAUgOH7-YpmtxjTj32AdwuCMIcGJkq9WWbXlkbsSul0avjvhkniEs-t856cnG8PAOA-ZPllyVjdaFe4T8N9cAV86F-8oTGqKkpXEFv9Q94aZXlRCsdthygMQwxhv1EV104JdS7snvTwUL0W3YXf7QBChGKI4n6iZIeLCR3Pl9dGrMUwj1iyqvSNXNMmmyU5HQ6mVjwumjs5truYbkcbTeR8m6RCRLssu0*pfVrepvmgbdhzFr1MP7gLZ-ir3qxkPGlZsB-1Tjr1xs-vBBBHJA5wT9*5PahadwGGKESYwNP43tH7ARZeXFI_");
var result = await _dim.imLogin(1400117017, "rq2",
"eJxlz01Pg0AQgOE7v4Ls2ejMwnaxSQ9Sq60W09o2QS*ElKGsHxS2SxGM-92ITSRxrs87mcynZds2W89X5-F2u69yE5mmIGYPbQbs7A*LQiVRbCJHJ-*QPgqlKYpTQ7pDFEJwgH6jEsqNStWp0CXv4SF5jboLv9suAKIElP1E7ToMJsvx7HpuKGhhJ1J3WU-Tl0E1fp6oMPPC9SNlOHiqFhftBmdhvLhSvi-L*yn4spG5vinfNGUplu2x8bmHCbmeaaugvn248zb1aNQ7adQ7nd5xgaO8dLyeHkkf1D7vAg4okDvwM8z6sr4BAlVcKw__");
print(result);
} on PlatformException {
print("登录 失败");
}
}
Future<void> logout() async {
try {
var result = await _dim.imLogout();
print(result);
} on PlatformException {
print("登出 失败");
}
}
Future<dynamic> getMessages() async {
try {
var result = await _dim.getMessages(
"rq3",
);
print(result);
} on PlatformException {}
}
void canCelListener() {
if (_messageStreamSubscription != null) {
_messageStreamSubscription.cancel();
}
}
void getUserInfo() async {
try {
List<String> users = List();
users.add("jiumi_1");
var result = await _dim.getUsersProfile(users);
print(result);
} on PlatformException {
print("获取个人资料失败");
}
}
}
Add this to your package's pubspec.yaml file:
dependencies:
dim: ^0.1.19
You can install packages from the command line:
with Flutter:
$ flutter packages get
Alternatively, your editor might support flutter packages get
.
Check the docs for your editor to learn more.
Now in your Dart code, you can use:
import 'package:dim/dim.dart';
Version | Uploaded | Documentation | Archive |
---|---|---|---|
0.1.19 | Nov 13, 2018 |
|
|
0.1.18 | Nov 5, 2018 |
|
|
0.1.17 | Nov 5, 2018 |
|
|
0.1.16 | Nov 5, 2018 |
|
|
0.1.15 | Nov 5, 2018 |
|
|
0.1.14 | Nov 5, 2018 |
|
|
0.1.13 | Nov 1, 2018 |
|
|
0.1.12 | Oct 30, 2018 |
|
|
0.1.11 | Oct 30, 2018 |
|
|
0.1.10 | Oct 30, 2018 |
|
|
Popularity:
Describes how popular the package is relative to other packages.
[more]
|
43
|
Health:
Code health derived from static analysis.
[more]
|
100
|
Maintenance:
Reflects how tidy and up-to-date the package is.
[more]
|
60
|
Overall:
Weighted score of the above.
[more]
|
64
|
We analyzed this package on Feb 14, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:
Detected platforms: Flutter
References Flutter, and has no conflicting libraries.
Format lib/manger.dart
.
Run flutter format
to format lib/manger.dart
.
Support the latest stable Dart SDK in pubspec.yaml
. (-20 points)
The SDK constraint in pubspec.yaml
doesn't allow the latest stable Dart SDK release.
The description contains too many non-ASCII characters. (-20 points)
The site uses English as its primary language. The value of the description
field in your package's pubspec.yaml
field should primarily contain characters used in English.
Package | Constraint | Resolved | Available |
---|---|---|---|
Direct dependencies | |||
Dart SDK | >=1.19.0 < 2.2.0 | ||
flutter | 0.0.0 | ||
Transitive dependencies | |||
collection | 1.14.11 | ||
meta | 1.1.6 | 1.1.7 | |
sky_engine | 0.0.99 | ||
typed_data | 1.1.6 | ||
vector_math | 2.0.8 |