AjFlutterAppspPlugin.m 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #import "AjFlutterAppspPlugin.h"
  2. #import <AJSDKAppSp/AJSDKAppSp-Swift.h>
  3. @implementation AjFlutterAppspPlugin
  4. + (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
  5. FlutterMethodChannel* channel = [FlutterMethodChannel
  6. methodChannelWithName:@"aj_flutter_appsp"
  7. binaryMessenger:[registrar messenger]];
  8. AjFlutterAppspPlugin* instance = [[AjFlutterAppspPlugin alloc] init];
  9. [registrar addMethodCallDelegate:instance channel:channel];
  10. }
  11. - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
  12. // 版本更新
  13. if ([call.method isEqualToString: @"getUpdateModel"]) {
  14. NSString *appKey = call.arguments[@"appKey"];
  15. [[AppSpService shareService] setAppkeyWithAppKey:appKey];
  16. __weak typeof(self) weakSelf = self;
  17. [[AppSpService shareService] checkVersionUpdateWithSuccess:^(NSDictionary* repData) {
  18. result([weakSelf formateDictToJSonString:repData]);
  19. } failure:^(NSDictionary* errorData) {
  20. result([weakSelf formateDictToJSonString:errorData]);
  21. }];
  22. } else if ([call.method isEqualToString:@"getNoticeModel"]) {//通知栏
  23. NSString *appKey = call.arguments[@"appKey"];
  24. [[AppSpService shareService] setAppkeyWithAppKey:appKey];
  25. __weak typeof(self) weakSelf = self;
  26. [[AppSpService shareService] getNoticeInfoWithSuccess:^(NSDictionary* repData) {
  27. result([weakSelf formateDictToJSonString:repData]);
  28. } failure:^(NSDictionary* errorData) {
  29. result([weakSelf formateDictToJSonString:errorData]);
  30. }];
  31. } else {
  32. result(FlutterMethodNotImplemented);
  33. }
  34. }
  35. //字典转jsonstring
  36. - (NSString *)formateDictToJSonString:(NSDictionary*) dict {
  37. NSError * error = nil;
  38. NSData * jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:&error];
  39. NSString * jsonStr = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
  40. if (error != nil) {
  41. return @"";
  42. } else {
  43. return jsonStr;
  44. }
  45. }
  46. @end