Hibok
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 
 

272 rader
10 KiB

  1. #include "AppDelegate.h"
  2. #include "GeneratedPluginRegistrant.h"
  3. #import "GoogleMaps/GoogleMaps.h"
  4. @implementation AppDelegate
  5. - (BOOL)application:(UIApplication *)application
  6. didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  7. [GMSServices provideAPIKey:@"AIzaSyAb9JNtW0BEZ_qLeDg87ZhvxSmZply-7hU"];
  8. FlutterViewController* controller = (FlutterViewController*)self.window.rootViewController;
  9. FlutterMethodChannel* channel = [FlutterMethodChannel
  10. methodChannelWithName:@"make.photo.screen.hibok"
  11. binaryMessenger:controller];
  12. [channel setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) {
  13. if ([@"makePhotoScreen" isEqualToString:call.method]) {
  14. UIImage* img = [self makePhotoScreen: controller.view];
  15. NSData *imageData = UIImageJPEGRepresentation(img, 0.8);
  16. FlutterStandardTypedData* value = [FlutterStandardTypedData typedDataWithBytes:imageData];
  17. result(value);
  18. }else if([@"openMapForOth" isEqualToString:call.method]){
  19. NSDictionary* params = call.arguments;
  20. NSString* mapType = params[@"mapType"];
  21. NSArray* latLng = params[@"latLng"];
  22. NSString* address = params[@"address"];
  23. [self openMapForOth:mapType latLng:latLng adress:address];
  24. }else if([@"getListForMap" isEqualToString:call.method]){
  25. NSArray* supportMaps = [self getListForMap];
  26. result(supportMaps);
  27. }
  28. else
  29. {
  30. result(FlutterMethodNotImplemented);
  31. }
  32. }];
  33. // 创建eventChannel 代理方法里处理stream流 delegate设置为self
  34. FlutterEventChannel *eventChannel = [FlutterEventChannel eventChannelWithName:@"com.file.hibok" binaryMessenger:controller];
  35. [eventChannel setStreamHandler:self];
  36. [GeneratedPluginRegistrant registerWithRegistry:self];
  37. if(![[NSUserDefaults standardUserDefaults]objectForKey:@"Notification"]){
  38. [[UIApplication sharedApplication] cancelAllLocalNotifications];
  39. [[NSUserDefaults standardUserDefaults]setBool:YES forKey:@"Notification"];
  40. }
  41. // Override point for customization after application launch.
  42. return [super application:application didFinishLaunchingWithOptions:launchOptions];
  43. }
  44. #pragma mark - FlutterStreamHandler
  45. - (FlutterError* _Nullable)onListenWithArguments:(id _Nullable)arguments
  46. eventSink:(FlutterEventSink)eventSink{
  47. self.eventSink = eventSink;
  48. return nil;
  49. }
  50. - (FlutterError* _Nullable)onCancelWithArguments:(id _Nullable)arguments {
  51. return nil;
  52. }
  53. - (UIImage*)makePhotoScreen:(UIView*)view {
  54. CGSize size = view.bounds.size;
  55. UIGraphicsBeginImageContextWithOptions(size, NO, 0.0);
  56. [view drawViewHierarchyInRect:view.bounds afterScreenUpdates:YES];
  57. UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
  58. UIGraphicsEndImageContext();
  59. // CGImageRef imageRef =image.CGImage;
  60. // CGRect rect = CGRectMake(CGImageGetWidth(imageRef)/4, CGImageGetHeight(imageRef)/2-CGImageGetWidth(imageRef)/2, CGImageGetWidth(imageRef)/2, CGImageGetWidth(imageRef)/2);//这里可以设置想要截图的区域
  61. //
  62. // CGImageRef imageRefRect =CGImageCreateWithImageInRect(imageRef, rect);
  63. //
  64. // UIImage *sendImage =[[UIImage alloc] initWithCGImage:imageRefRect];
  65. //
  66. //
  67. return image;
  68. }
  69. - (NSArray*)getListForMap{
  70. NSMutableArray* maps = [[NSMutableArray alloc] init];
  71. //苹果地图
  72. [maps addObject:@"apple"];
  73. //谷歌地图
  74. if([[UIApplication sharedApplication]canOpenURL:[NSURL URLWithString:@"comgooglemaps://"]]) {
  75. [maps addObject:@"google"];
  76. }
  77. //高德地图
  78. if([[UIApplication sharedApplication]canOpenURL:[NSURL URLWithString:@"iosamap://"]]) {
  79. [maps addObject:@"minimap"];
  80. }
  81. //百度地图
  82. if([[UIApplication sharedApplication]canOpenURL:[NSURL URLWithString:@"baidumap://"]]) {
  83. [maps addObject:@"baidu"];
  84. }
  85. return maps;
  86. }
  87. -(void) openMapForOth:(NSString *)mapType latLng:(NSArray*)latLng adress:(NSString*)adress {
  88. if([mapType isEqualToString:@"baidu"]){
  89. NSString*urlString = [[NSString stringWithFormat:@"baidumap://map/geocoder?location=%@f,%@f&coord_type=gcj02&src=com.cyhd.henhoandroid",latLng.firstObject, latLng.lastObject] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
  90. [[UIApplication sharedApplication] openURL: [NSURL URLWithString:urlString]];
  91. }else if([mapType isEqualToString:@"minimap"]){
  92. NSString*urlString = [[NSString stringWithFormat:@"iosamap://navi?sourceApplication= &lat=%@f&lon=%@f&dev=1",latLng.firstObject, latLng.lastObject] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
  93. [[UIApplication sharedApplication] openURL: [NSURL URLWithString:urlString]];
  94. }else if([mapType isEqualToString:@"apple"]){
  95. NSString*urlString = [[NSString stringWithFormat:@"http://maps.apple.com/?daddr=%@f,%@f",latLng.firstObject, latLng.lastObject] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
  96. [[UIApplication sharedApplication] openURL: [NSURL URLWithString:urlString]];
  97. }else if([mapType isEqualToString:@"google"]){
  98. NSString*urlString = [[NSString stringWithFormat:@"comgooglemaps://?daddr=%@f,%@f",latLng.firstObject, latLng.lastObject] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
  99. [[UIApplication sharedApplication] openURL: [NSURL URLWithString:urlString]];
  100. }
  101. }
  102. - (void)applicationDidEnterBackground:(UIApplication *)application {
  103. self.task = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
  104. [[UIApplication sharedApplication] endBackgroundTask:self.task];
  105. self.task = UIBackgroundTaskInvalid;
  106. }];
  107. // __block int count = 0;
  108. // [NSTimer scheduledTimerWithTimeInterval:1 repeats:YES block:^(NSTimer * _Nonnull timer) {
  109. //
  110. // count ++;
  111. // NSLog(@"%d",count);
  112. //
  113. // }];
  114. }
  115. //申请后台运行权限
  116. - (void)backGroundSpeech {
  117. UIApplication *app = [UIApplication sharedApplication];
  118. __block UIBackgroundTaskIdentifier bgTask;
  119. bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
  120. dispatch_async(dispatch_get_main_queue(), ^{
  121. if (bgTask != UIBackgroundTaskInvalid)
  122. {
  123. bgTask = UIBackgroundTaskInvalid;
  124. }
  125. });
  126. }];
  127. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  128. dispatch_async(dispatch_get_main_queue(), ^{
  129. if (bgTask != UIBackgroundTaskInvalid)
  130. {
  131. bgTask = UIBackgroundTaskInvalid;
  132. }
  133. });
  134. });
  135. }
  136. #pragma mark ------------------ 结束后台任务 ------------------
  137. - (void)endBackgroundUpdateask{
  138. [[UIApplication sharedApplication] endBackgroundTask:self.task];
  139. self.task = UIBackgroundTaskInvalid;
  140. }
  141. - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString*, id> *)options
  142. {
  143. NSLog(@"myurl %@",url.absoluteString);
  144. // if (url != nil) {
  145. //// 不跟分享插件冲突
  146. // if ([url.absoluteString containsString:@"SharePhotos"]) {
  147. // NSLog(@"myurl 存在");
  148. //
  149. // }
  150. // }
  151. if (url != nil && [url.absoluteString containsString:@"file:///private"]) {
  152. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  153. NSString *documentsDirectory = [paths lastObject];
  154. if (url != nil) {
  155. NSString *path = [url absoluteString];
  156. path = [path stringByRemovingPercentEncoding];
  157. NSMutableString *string = [[NSMutableString alloc] initWithString:path];
  158. if ([path hasPrefix:@"file:///private"]) {
  159. [string replaceOccurrencesOfString:@"file:///private" withString:@"" options:NSCaseInsensitiveSearch range:NSMakeRange(0, path.length)];
  160. }
  161. NSArray *tempArray = [string componentsSeparatedByString:@"/"];
  162. NSString *fileName = tempArray.lastObject;
  163. NSString *sourceName = options[@"UIApplicationOpenURLOptionsSourceApplicationKey"];
  164. NSFileManager *fileManager = [NSFileManager defaultManager];
  165. NSString *filePath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@",fileName]];
  166. if ([fileManager fileExistsAtPath:filePath]) {
  167. NSLog(@"文件已存在");
  168. self.eventSink(filePath);
  169. // [SVProgressHUD showErrorWithStatus:@"文件已存在"];
  170. return YES;
  171. }
  172. // [MRTools creatFilePathInManager:sourceName];
  173. BOOL isSuccess = [fileManager copyItemAtPath:string toPath:filePath error:nil];
  174. if (isSuccess == YES) {
  175. NSLog(@"拷贝成功");
  176. self.eventSink(filePath);
  177. // [SVProgressHUD showSuccessWithStatus:@"文件拷贝成功"];
  178. } else {
  179. NSLog(@"拷贝失败");
  180. // [SVProgressHUD showErrorWithStatus:@"文件拷贝失败"];
  181. }
  182. }
  183. }else{
  184. [super application:self openURL:url options:nil];
  185. return YES;
  186. }
  187. NSLog(@"application:openURL:options:");
  188. return YES;
  189. }
  190. @end