Commit 3c95241b authored by 汪林玲's avatar 汪林玲

整合iOS到flutter 插件中

parent 0dcdfcf6
...@@ -29,9 +29,7 @@ public class JdsdkPlugin implements FlutterPlugin, MethodCallHandler, ActivityAw ...@@ -29,9 +29,7 @@ public class JdsdkPlugin implements FlutterPlugin, MethodCallHandler, ActivityAw
@Override @Override
public void onMethodCall( MethodCall call, Result result) { public void onMethodCall( MethodCall call, Result result) {
if (call.method.equals("getPlatformVersion")) { if (call.method.equals("init")) {
result.success("Android " + android.os.Build.VERSION.RELEASE);
} else if (call.method.equals("init")) {
mJDHelper.initKepler(call,result); mJDHelper.initKepler(call,result);
}else if (call.method.equals("openUrl")) { }else if (call.method.equals("openUrl")) {
Log.d("flutter-test","openUrl"); Log.d("flutter-test","openUrl");
......
4ee6262d6df4eae39aef50da3587f661 9b225167b750ff91e229b9ed7eda1696
\ No newline at end of file \ No newline at end of file
PODS: PODS:
- Flutter (1.0.0) - Flutter (1.0.0)
- jdsdk (0.0.1): - jd_sdk (1.0.0):
- Flutter - Flutter
DEPENDENCIES: DEPENDENCIES:
- Flutter (from `Flutter`) - Flutter (from `Flutter`)
- jdsdk (from `.symlinks/plugins/jdsdk/ios`) - jd_sdk (from `.symlinks/plugins/jd_sdk/ios`)
EXTERNAL SOURCES: EXTERNAL SOURCES:
Flutter: Flutter:
:path: Flutter :path: Flutter
jdsdk: jd_sdk:
:path: ".symlinks/plugins/jdsdk/ios" :path: ".symlinks/plugins/jd_sdk/ios"
SPEC CHECKSUMS: SPEC CHECKSUMS:
Flutter: 0e3d915762c693b495b44d77113d4970485de6ec Flutter: 0e3d915762c693b495b44d77113d4970485de6ec
jdsdk: 33a8f56cd92bebbe1fece516e092aa22bd0e6a8b jd_sdk: 795291e67471d1924fd27717221a445dd4ffec09
PODFILE CHECKSUM: 1e5bdb5d3f5df2396887ecffd613804a61b33078 PODFILE CHECKSUM: 1e5bdb5d3f5df2396887ecffd613804a61b33078
......
...@@ -198,7 +198,7 @@ ...@@ -198,7 +198,7 @@
TargetAttributes = { TargetAttributes = {
97C146ED1CF9000F007C117D = { 97C146ED1CF9000F007C117D = {
CreatedOnToolsVersion = 7.3.1; CreatedOnToolsVersion = 7.3.1;
DevelopmentTeam = ZMCJ78285X; DevelopmentTeam = 4R6KK56452;
}; };
}; };
}; };
...@@ -392,7 +392,7 @@ ...@@ -392,7 +392,7 @@
buildSettings = { buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = ZMCJ78285X; DEVELOPMENT_TEAM = 4R6KK56452;
ENABLE_BITCODE = NO; ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = ( FRAMEWORK_SEARCH_PATHS = (
"$(inherited)", "$(inherited)",
...@@ -404,7 +404,7 @@ ...@@ -404,7 +404,7 @@
"$(inherited)", "$(inherited)",
"$(PROJECT_DIR)/Flutter", "$(PROJECT_DIR)/Flutter",
); );
PRODUCT_BUNDLE_IDENTIFIER = com.youliapp; PRODUCT_BUNDLE_IDENTIFIER = com.youliapp.test;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
VERSIONING_SYSTEM = "apple-generic"; VERSIONING_SYSTEM = "apple-generic";
}; };
...@@ -521,7 +521,7 @@ ...@@ -521,7 +521,7 @@
buildSettings = { buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = ZMCJ78285X; DEVELOPMENT_TEAM = 4R6KK56452;
ENABLE_BITCODE = NO; ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = ( FRAMEWORK_SEARCH_PATHS = (
"$(inherited)", "$(inherited)",
...@@ -533,7 +533,7 @@ ...@@ -533,7 +533,7 @@
"$(inherited)", "$(inherited)",
"$(PROJECT_DIR)/Flutter", "$(PROJECT_DIR)/Flutter",
); );
PRODUCT_BUNDLE_IDENTIFIER = com.youliapp; PRODUCT_BUNDLE_IDENTIFIER = com.youliapp.test;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
VERSIONING_SYSTEM = "apple-generic"; VERSIONING_SYSTEM = "apple-generic";
}; };
...@@ -545,7 +545,7 @@ ...@@ -545,7 +545,7 @@
buildSettings = { buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = ZMCJ78285X; DEVELOPMENT_TEAM = 4R6KK56452;
ENABLE_BITCODE = NO; ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = ( FRAMEWORK_SEARCH_PATHS = (
"$(inherited)", "$(inherited)",
...@@ -557,7 +557,7 @@ ...@@ -557,7 +557,7 @@
"$(inherited)", "$(inherited)",
"$(PROJECT_DIR)/Flutter", "$(PROJECT_DIR)/Flutter",
); );
PRODUCT_BUNDLE_IDENTIFIER = com.youliapp; PRODUCT_BUNDLE_IDENTIFIER = com.youliapp.test;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
VERSIONING_SYSTEM = "apple-generic"; VERSIONING_SYSTEM = "apple-generic";
}; };
......
...@@ -2,7 +2,7 @@ import 'package:flutter/material.dart'; ...@@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
import 'dart:async'; import 'dart:async';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:jdsdk/jdsdk.dart'; import 'package:jd_sdk/jdsdk.dart';
void main() => runApp(MyApp()); void main() => runApp(MyApp());
...@@ -12,32 +12,9 @@ class MyApp extends StatefulWidget { ...@@ -12,32 +12,9 @@ class MyApp extends StatefulWidget {
} }
class _MyAppState extends State<MyApp> { class _MyAppState extends State<MyApp> {
String _platformVersion = 'Unknown';
@override @override
void initState() { void initState() {
super.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 Jdsdk.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;
setState(() {
_platformVersion = platformVersion;
});
} }
@override @override
...@@ -50,33 +27,29 @@ class _MyAppState extends State<MyApp> { ...@@ -50,33 +27,29 @@ class _MyAppState extends State<MyApp> {
body: Column( body: Column(
children: <Widget>[ children: <Widget>[
InkWell( InkWell(
onTap: ()async{ onTap: () async {
//android //android
var result= await Jdsdk.init(appKey: '', appSecret: ''); var result = await Jdsdk.init(appKey: '', appSecret: '');
print(result); print(result);
}, },
child: Center( child: Center(
child: Text( child: Text('测试初迟化'),
'测试初迟化'
),
), ),
), ),
SizedBox( SizedBox(
height: 100, height: 100,
), ),
InkWell( InkWell(
onTap: ()async{ onTap: () async {
var result = await Jdsdk.openUrl( url: 'https://item.m.jd.com/product/100009963992.html?wxa_abtest=o&utm_user=plusmember&ad_od=share&utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=CopyURL'); var result = await Jdsdk.openUrl(
url:
'https://item.m.jd.com/product/100009963992.html?wxa_abtest=o&utm_user=plusmember&ad_od=share&utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=CopyURL');
print(result); print(result);
}, },
child: Center( child: Center(
child: Text( child: Text('测试打开京东'),
'测试打开京东'
),
), ),
), ),
], ],
), ),
), ),
......
...@@ -67,7 +67,7 @@ packages: ...@@ -67,7 +67,7 @@ packages:
description: flutter description: flutter
source: sdk source: sdk
version: "0.0.0" version: "0.0.0"
jdsdk: jd_sdk:
dependency: "direct dev" dependency: "direct dev"
description: description:
path: ".." path: ".."
......
...@@ -17,7 +17,7 @@ dev_dependencies: ...@@ -17,7 +17,7 @@ dev_dependencies:
flutter_test: flutter_test:
sdk: flutter sdk: flutter
jdsdk: jd_sdk:
path: ../ path: ../
# For information on the generic Dart part of this file, see the # For information on the generic Dart part of this file, see the
......
#import "JdsdkPlugin.h" #import "JdsdkPlugin.h"
#import "JDSDK/JDKeplerSDK.h"
@interface JdsdkPlugin() @interface JdsdkPlugin()
@end @end
@implementation JdsdkPlugin @implementation JdsdkPlugin
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar { + (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
NSLog(@"registerWithRegistrar"); FlutterMethodChannel* channel = [FlutterMethodChannel methodChannelWithName:@"jdsdk" binaryMessenger:[registrar messenger]];
FlutterMethodChannel* channel = [FlutterMethodChannel
methodChannelWithName:@"jdsdk"
binaryMessenger:[registrar messenger]];
JdsdkPlugin* instance = [[JdsdkPlugin alloc] init]; JdsdkPlugin* instance = [[JdsdkPlugin alloc] init];
//将 JdsdkPlugin 的无参 init 函数调整为 initWithRegistrar
// JdsdkPlugin* instance = [[JdsdkPlugin alloc] initWithRegistrar:registrar];
[registrar addMethodCallDelegate:instance channel:channel]; [registrar addMethodCallDelegate:instance channel:channel];
} }
- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
if ([@"getPlatformVersion" isEqualToString:call.method]) { if ([@"init" isEqualToString:call.method]) {
result([@"iOS " stringByAppendingString:[[UIDevice currentDevice] systemVersion]]); NSString *appKey = call.arguments[@"appKey"];
NSString *appSecret = call.arguments[@"appSecret"];
[[KeplerApiManager sharedKPService]asyncInitSdk:appKey secretKey:appSecret sucessCallback:^(){
result(@"{status:1}");
}failedCallback:^(NSError *error){
result(@"{status:0}");
}];
} else if([@"openUrl" isEqualToString:call.method]){
NSString *url = call.arguments[@"url"];
//判断是否安装京东app
if ([[UIApplication sharedApplication]canOpenURL:[NSURL URLWithString:[NSString stringWithFormat:@"openapp.jdmobile://"]]]) {
[[KeplerApiManager sharedKPService]openKeplerPageWithURL:url userInfo:nil successCallback:^{
result(@"{status:1}");
} failedCallback:^(NSInteger code, NSString * _Nonnull url) {
result(@"{status:0}");
}];
}else{
result(@"{status:0}");
}
} else { } else {
result(FlutterMethodNotImplemented); result(FlutterMethodNotImplemented);
} }
......
//
// JDKeplerSDK.h
// JDKeplerSDK
//
// Created by JD.K on 16/3/15.
// Copyright © 2016年 JD.K. All rights reserved.
//
#import <UIKit/UIKit.h>
//! Project version number for JDKeplerSDK.
FOUNDATION_EXPORT double JDKeplerSDKVersionNumber;
//! Project version string for JDKeplerSDK.
FOUNDATION_EXPORT const unsigned char JDKeplerSDKVersionString[];
// In this header, you should import all the public headers of your framework using statements like #import <JDKeplerSDK/PublicHeader.h>
#import<JDSDK/KeplerApiManager.h>
//
// KeplerApiManager.h
// KeplerApp
// 提供Kepler服务
// Created by JD.K on 16/6/20.
// Copyright © 2016年 JD.K. All rights reserved.
// version 3.0.1
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
/** 初始化成功回调 */
typedef void (^initSuccessCallback)();
/** 初始化失败回调 */
typedef void (^initFailedCallback)(NSError * _Nonnull error);
/**
打开成功回调
*/
typedef void(^OpenSuccessBlock)();
/**
* 响应失败的错误回调,返回一个错误的链接或信息
*/
typedef void(^OpenFailedBlock)(NSInteger code, NSString * _Nonnull url);
typedef enum {
KeplerErrorCodeUnInstalled = 422, //未安装京东app
KeplerErrorCodeWhited, //本地url不在白名单中
KeplerErrorCodeResponsed, //本地呼起open协议失败
KeplerErrorCodeNoSid, //sid为空
KeplerErrorCodeInValidApp //应用不合法
} KeplerErrorCode;
@interface KeplerApiManager : NSObject
/**
分佣的 AppKey2
*/
@property (nonatomic, copy) NSString *secondAppKey;
//********************************* 通过京东APP打开链接相关参数 ************************************
/**
当isOpenByH5为 NO 时,准备跳转到JD APP时会调用这些代码。可以把开启 Loading动画的代码放到这里
为避免造成混乱,在关闭Kepler界面时,会置为nil。因此需要在每次打开Kepler之前单独设置。
*/
@property (nonatomic, copy) void(^startOpenJDAppBlock)();
/**
当isOpenByH5为 NO 时,跳转JD APP准备工作完成时会调用这些代码,success为YES表示成功,可以打开JD APP,为NO时表示打开失败。
为避免造成混乱,在关闭Kepler界面时,会置为nil。因此需要在每次打开Kepler之前单独设置。
update: success为NO且错误码等于-1005时,安全id为空
*/
@property (nonatomic, copy) void(^finishOpenJDAppBlock)(BOOL success,NSError *error);
/**
* 京东达人内容ID 关闭kepler界面时会清除 如果需要此值 再次打开需要再次设置
**/
@property (nonatomic, copy) NSString *actId;
/**
* 京东达人 内容渠道扩展字段 关闭kepler界面时会清除 如果需要此值 再次打开需要再次设置
**/
@property (nonatomic, copy) NSString *ext;
/**
* 是否走服务端的渠道,默认走本地渠道
*/
@property (nonatomic, assign) BOOL isServerChannel;
/**
打开京东超时时间设置 关闭 Kepler 界面时不会重置 默认为60
*/
@property (nonatomic, assign) NSTimeInterval openJDTimeout;
//*******************************************************************************************************
/**
* KeplerApiManager 单例
*
* @return KeplerApiManager 单例
*/
+ (KeplerApiManager *)sharedKPService;
/**
* 注册Kepler 服务
*
* @param appKey 注册的appKey
* @param appSecret 注册的secretKey
*/
- (void)asyncInitSdk:(NSString *)appKey
secretKey:(NSString *)appSecret
sucessCallback:(initSuccessCallback)sucessCallback
failedCallback:(initFailedCallback)failedCallback;
/**
跳转京东app
@param url 调用方传入的URl参数
@param userInfo 调用sdk时传入的kepler自定义参数
@param failedCallback code 表示错误编码, url 引起调用失败的url
*/
- (void)openKeplerPageWithURL:(NSString *)url
userInfo:(NSDictionary *)userInfo
successCallback:(OpenSuccessBlock _Nullable)success
failedCallback:(OpenFailedBlock _Nonnull)failure;
@end
framework module JDKeplerSDK {
umbrella header "JDKeplerSDK.h"
export *
module * { export * }
}
...@@ -3,8 +3,8 @@ ...@@ -3,8 +3,8 @@
# Run `pod lib lint jdsdk.podspec' to validate before publishing. # Run `pod lib lint jdsdk.podspec' to validate before publishing.
# #
Pod::Spec.new do |s| Pod::Spec.new do |s|
s.name = 'jdsdk' s.name = 'jd_sdk'
s.version = '0.0.1' s.version = '1.0.0'
s.summary = 'A new Flutter plugin.' s.summary = 'A new Flutter plugin.'
s.description = <<-DESC s.description = <<-DESC
A new Flutter plugin. A new Flutter plugin.
...@@ -15,11 +15,18 @@ A new Flutter plugin. ...@@ -15,11 +15,18 @@ A new Flutter plugin.
s.source = { :path => '.' } s.source = { :path => '.' }
s.source_files = 'Classes/**/*' s.source_files = 'Classes/**/*'
s.public_header_files = 'Classes/**/*.h' s.public_header_files = 'Classes/**/*.h'
s.dependency 'Flutter'
# 京东导入 # 京东导入
s.platform = :ios, '10.0' s.preserve_paths = 'JDSDK.framework'
s.xcconfig = { 'OTHER_LDFLAGS' => '-framework JDSDK' }
s.vendored_frameworks = 'Framework/JDSDK.framework'
s.platform = :ios, '8.0'
s.dependency 'Flutter'
s.static_framework = true
s.libraries = "c++.tbd"
s.libraries = "z"
# Flutter.framework does not contain a i386 slice. Only x86_64 simulators are supported. # Flutter.framework does not contain a i386 slice. Only x86_64 simulators are supported.
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'VALID_ARCHS[sdk=iphonesimulator*]' => 'x86_64' } s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'VALID_ARCHS[sdk=iphonesimulator*]' => 'x86_64' }
......
...@@ -5,12 +5,11 @@ import 'package:flutter/services.dart'; ...@@ -5,12 +5,11 @@ import 'package:flutter/services.dart';
class Jdsdk { class Jdsdk {
static const MethodChannel _channel = const MethodChannel('jdsdk'); static const MethodChannel _channel = const MethodChannel('jdsdk');
static Future<String> get platformVersion async { ///
final String version = await _channel.invokeMethod('getPlatformVersion'); /// 初始化京东sdk
return version; /// [appKey] appKey
} /// [appSecret] app密钥
///
///初始化sdk
static Future<String> init( static Future<String> init(
{@required String appKey, @required String appSecret}) async { {@required String appKey, @required String appSecret}) async {
final String version = await _channel final String version = await _channel
...@@ -18,7 +17,10 @@ class Jdsdk { ...@@ -18,7 +17,10 @@ class Jdsdk {
return version; return version;
} }
///打开京东任意url ///
/// 打开京东的任意URL
/// [url] 待打开的url地址
///
static Future<String> openUrl({@required String url}) async { static Future<String> openUrl({@required String url}) async {
final String version = await _channel.invokeMethod('openUrl', {"url": url}); final String version = await _channel.invokeMethod('openUrl', {"url": url});
return version; return version;
......
name: jdsdk name: jd_sdk
description: The implementation of Jingdong SDK on Flutter, through which you can realize the wake-up Jingdong app to open any URL of Jingdong, including product details and other functions. description: The implementation of Jingdong SDK on Flutter, through which you can realize the wake-up Jingdong app to open any URL of Jingdong, including product details and other functions.
version: 0.0.1 version: 0.0.1
author: wuchaowen <chaowen1110@gmail.com> author: wuchaowen <chaowen1110@gmail.com>
......
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:jdsdk/jdsdk.dart';
void main() { void main() {
const MethodChannel channel = MethodChannel('jdsdk'); const MethodChannel channel = MethodChannel('jdsdk');
...@@ -16,8 +15,4 @@ void main() { ...@@ -16,8 +15,4 @@ void main() {
tearDown(() { tearDown(() {
channel.setMockMethodCallHandler(null); channel.setMockMethodCallHandler(null);
}); });
test('getPlatformVersion', () async {
expect(await Jdsdk.platformVersion, '42');
});
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment