mirror of
https://github.com/RxReader/tencent_kit.git
synced 2025-05-20 16:56:33 +08:00
修正GIF图片分享功能,修正音乐分享功能
This commit is contained in:
BIN
example/images/icon/2.0x/timg.gif
Normal file
BIN
example/images/icon/2.0x/timg.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 190 KiB |
@ -1,8 +1,10 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:fake_path_provider/fake_path_provider.dart';
|
||||
import 'package:fake_tencent/fake_tencent.dart';
|
||||
|
||||
void main() {
|
||||
@ -144,6 +146,28 @@ class _HomeState extends State<Home> {
|
||||
);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
title: const Text('图片分享'),
|
||||
onTap: () async {
|
||||
AssetImage image = const AssetImage('images/icon/timg.gif');
|
||||
AssetBundleImageKey key =
|
||||
await image.obtainKey(createLocalImageConfiguration(context));
|
||||
ByteData imageData = await key.bundle.load(key.name);
|
||||
Directory saveDir = await PathProvider.getDocumentsDirectory();
|
||||
File saveFile = File(
|
||||
'${saveDir.path}${path.separator}timg.gif');
|
||||
if (!saveFile.existsSync()) {
|
||||
saveFile.createSync(recursive: true);
|
||||
}
|
||||
saveFile.writeAsBytesSync(imageData.buffer.asUint8List(),
|
||||
flush: true);
|
||||
Uri imageUri = Uri.file(saveFile.path);
|
||||
await widget.tencent.shareImage(
|
||||
scene: TencentScene.SCENE_QQ,
|
||||
imageUri: imageUri,
|
||||
);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
title: const Text('分享链接'),
|
||||
onTap: () {
|
||||
|
@ -13,6 +13,7 @@ dependencies:
|
||||
# Use with the CupertinoIcons class for iOS style icons.
|
||||
cupertino_icons: ^0.1.2
|
||||
|
||||
fake_path_provider: ^0.0.1
|
||||
fake_tencent:
|
||||
path: ../
|
||||
|
||||
@ -34,9 +35,8 @@ flutter:
|
||||
uses-material-design: true
|
||||
|
||||
# To add assets to your application, add an assets section, like this:
|
||||
# assets:
|
||||
# - images/a_dot_burr.jpeg
|
||||
# - images/a_dot_ham.jpeg
|
||||
assets:
|
||||
- images/icon/timg.gif
|
||||
|
||||
# An image asset can refer to one or more resolution-specific "variants", see
|
||||
# https://flutter.io/assets-and-images/#resolution-aware.
|
||||
|
@ -148,11 +148,8 @@ static NSString * const SCHEME_FILE = @"file";
|
||||
NSMutableArray * imageDatas = [NSMutableArray array];
|
||||
if (imageUris != nil && imageUris.count > 0) {
|
||||
for (NSString * imageUri in imageUris) {
|
||||
UIImage *image = [UIImage imageWithContentsOfFile:[NSURL URLWithString:imageUri].path];
|
||||
NSData * imageData = UIImagePNGRepresentation(image);
|
||||
if (imageData == nil) {
|
||||
imageData = UIImageJPEGRepresentation(image, 1);
|
||||
}
|
||||
NSURL * imageUrl = [NSURL URLWithString:imageUri];
|
||||
NSData * imageData = [NSData dataWithContentsOfFile:imageUrl.path];
|
||||
[imageDatas addObject:imageData];
|
||||
}
|
||||
}
|
||||
@ -175,16 +172,9 @@ static NSString * const SCHEME_FILE = @"file";
|
||||
// NSString * appName = call.arguments[ARGUMENT_KEY_APPNAME];
|
||||
// NSNumber * extInt = call.arguments[ARGUMENT_KEY_EXTINT];
|
||||
|
||||
UIImage *image = [UIImage imageWithContentsOfFile:[NSURL URLWithString:imageUri].path];
|
||||
NSData * imageData = UIImagePNGRepresentation(image);
|
||||
NSData * thumbData = nil;
|
||||
if (imageData == nil) {
|
||||
imageData = UIImageJPEGRepresentation(image, 1);
|
||||
thumbData = UIImageJPEGRepresentation(image, 0.2);
|
||||
} else {
|
||||
thumbData = imageData;
|
||||
}
|
||||
QQApiImageObject * object = [QQApiImageObject objectWithData:imageData previewImageData:thumbData title:nil description:nil];
|
||||
NSURL * imageUrl = [NSURL URLWithString:imageUri];
|
||||
NSData * imageData = [NSData dataWithContentsOfFile:imageUrl.path];
|
||||
QQApiImageObject * object = [QQApiImageObject objectWithData:imageData previewImageData:nil title:nil description:nil];
|
||||
SendMessageToQQReq * req = [SendMessageToQQReq reqWithContent: object];
|
||||
[QQApiInterface sendReq:req];
|
||||
}
|
||||
@ -202,17 +192,14 @@ static NSString * const SCHEME_FILE = @"file";
|
||||
// NSNumber * extInt = call.arguments[ARGUMENT_KEY_EXTINT];
|
||||
if (scene.intValue == SCENE_QQ) {
|
||||
QQApiAudioObject * object = nil;
|
||||
NSURL * uri = [NSURL URLWithString:imageUri];
|
||||
if ([SCHEME_FILE isEqualToString:uri.scheme]) {
|
||||
UIImage *image = [UIImage imageWithContentsOfFile:uri.path];
|
||||
NSData * imageData = UIImagePNGRepresentation(image);
|
||||
if (imageData == nil) {
|
||||
imageData = UIImageJPEGRepresentation(image, 1);
|
||||
}
|
||||
NSURL * imageUrl = [NSURL URLWithString:imageUri];
|
||||
if ([SCHEME_FILE isEqualToString:imageUrl.scheme]) {
|
||||
NSData * imageData = [NSData dataWithContentsOfFile:imageUrl.path];
|
||||
object = [QQApiAudioObject objectWithURL:[NSURL URLWithString:targetUrl] title:title description:summary previewImageData:imageData];
|
||||
} else {
|
||||
object = [QQApiAudioObject objectWithURL:[NSURL URLWithString:targetUrl] title:title description:summary previewImageURL:[NSURL URLWithString:musicUrl]];
|
||||
object = [QQApiAudioObject objectWithURL:[NSURL URLWithString:targetUrl] title:title description:summary previewImageURL:imageUrl];
|
||||
}
|
||||
object.flashURL = [NSURL URLWithString:musicUrl];
|
||||
SendMessageToQQReq * req = [SendMessageToQQReq reqWithContent: object];
|
||||
[QQApiInterface sendReq:req];
|
||||
}
|
||||
@ -229,16 +216,12 @@ static NSString * const SCHEME_FILE = @"file";
|
||||
// NSNumber * extInt = call.arguments[ARGUMENT_KEY_EXTINT];
|
||||
|
||||
QQApiNewsObject * object = nil;
|
||||
NSURL * uri = [NSURL URLWithString:imageUri];
|
||||
if ([SCHEME_FILE isEqualToString:uri.scheme]) {
|
||||
UIImage *image = [UIImage imageWithContentsOfFile:uri.path];
|
||||
NSData * imageData = UIImagePNGRepresentation(image);
|
||||
if (imageData == nil) {
|
||||
imageData = UIImageJPEGRepresentation(image, 1);
|
||||
}
|
||||
NSURL * imageUrl = [NSURL URLWithString:imageUri];
|
||||
if ([SCHEME_FILE isEqualToString:imageUrl.scheme]) {
|
||||
NSData * imageData = [NSData dataWithContentsOfFile:imageUrl.path];
|
||||
object = [QQApiNewsObject objectWithURL:[NSURL URLWithString:targetUrl] title:title description:summary previewImageData:imageData];
|
||||
} else {
|
||||
object = [QQApiNewsObject objectWithURL:[NSURL URLWithString:targetUrl] title:title description:summary previewImageURL:[NSURL URLWithString:imageUri]];
|
||||
object = [QQApiNewsObject objectWithURL:[NSURL URLWithString:targetUrl] title:title description:summary previewImageURL:imageUrl];
|
||||
}
|
||||
SendMessageToQQReq * req = [SendMessageToQQReq reqWithContent: object];
|
||||
if (scene.intValue == SCENE_QQ) {
|
||||
|
Reference in New Issue
Block a user