智莺生活APP的阿里百川 Flutter 插件
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 
 
 

87 рядки
3.3 KiB

  1. #import "FlutterAlibcPlugin.h"
  2. #import "FlutterAlibcHandle.h"
  3. #import <AlibcTradeSDK/AlibcTradeSDK.h>
  4. @interface FlutterAlibcPlugin()
  5. //一个handle服务
  6. @property(nonatomic,strong)FlutterAlibcHandle *handler;
  7. //一个service服务
  8. @end
  9. @implementation FlutterAlibcPlugin
  10. + (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
  11. FlutterMethodChannel* channel = [FlutterMethodChannel
  12. methodChannelWithName:@"flutter_alibc"
  13. binaryMessenger:[registrar messenger]];
  14. FlutterAlibcPlugin* instance = [[FlutterAlibcPlugin alloc] initWithRegistrar:registrar methodChannel:channel];
  15. [registrar addMethodCallDelegate:instance channel:channel];
  16. [registrar addApplicationDelegate:instance];
  17. }
  18. - (instancetype)initWithRegistrar:(NSObject <FlutterPluginRegistrar> *)registrar methodChannel:(FlutterMethodChannel *)flutterMethodChannel{
  19. self = [super init];
  20. if (self) {
  21. self.handler = [[FlutterAlibcHandle alloc]init];
  22. }
  23. return self;
  24. }
  25. - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
  26. if ([@"getPlatformVersion" isEqualToString:call.method]) {
  27. result([@"iOS " stringByAppendingString:[[UIDevice currentDevice] systemVersion]]);
  28. }else if ([@"initAlibc" isEqualToString:call.method]){
  29. [_handler initAlibc:call result:result];
  30. }else if([@"loginTaoBao" isEqualToString:call.method]){
  31. [_handler loginTaoBao:call result:result];
  32. }else if([@"taoKeLogin" isEqualToString:call.method]){
  33. [_handler taoKeLogin:call result:result];
  34. }else if([@"loginOut" isEqualToString:call.method]){
  35. [_handler loginOut];
  36. }else if([@"openByUrl" isEqualToString:call.method]){
  37. [_handler openByUrl:call result:result];
  38. }else if([@"openItemDetail" isEqualToString:call.method]){
  39. [_handler openItemDetail:call result:result];
  40. }else if([@"openShop" isEqualToString:call.method]){
  41. [_handler openShop:call result:result];
  42. }else if([@"openCart" isEqualToString:call.method]){
  43. [_handler openCart:call result:result];
  44. }else if([@"syncForTaoke" isEqualToString:call.method]){
  45. [_handler syncForTaoke:call result:result];
  46. }else if([@"useAlipayNative" isEqualToString:call.method]){
  47. [_handler useAlipayNative:call result:result];
  48. }else {
  49. result(FlutterMethodNotImplemented);
  50. }
  51. }
  52. #pragma mark -- 下面两个为百川处理应用跳转
  53. - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{
  54. // 如果百川处理过会返回YES
  55. if (![[AlibcTradeSDK sharedInstance] application:application openURL:url sourceApplication:sourceApplication annotation:annotation]) {
  56. return YES;
  57. }
  58. return NO;
  59. }
  60. //IOS9.0 系统新的处理openURL 的API
  61. - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options {
  62. if (@available(iOS 9.0, *)) {
  63. __unused BOOL isHandledByALBBSDK=[[AlibcTradeSDK sharedInstance] application:application openURL:url options:options];
  64. return isHandledByALBBSDK;
  65. } else {
  66. // Fallback on earlier versions
  67. }//处理其他app跳转到自己的app,如果百川处理过会返回YES
  68. return NO;
  69. }
  70. @end