// // UUIDManager.m // Unity-iPhone // // Created by fotoable on 2020/6/29. // #import #import "NativeTool.h" //#import "JKRBDMuteSwitch/RBDMuteSwitch.h" @implementation NativeTool BoolResultDel resultDel; static NativeTool *mInstance; +(NativeTool *)getInstance { if (mInstance == nil) { mInstance = [[NativeTool alloc] init]; } return mInstance; } -(void)shake:(int)pType Intensity:(float)pIntensity { UIImpactFeedbackStyle tStyle = UIImpactFeedbackStyleLight; if(pType == 1) { tStyle = UIImpactFeedbackStyleMedium; } else if(pType == 2) { tStyle = UIImpactFeedbackStyleHeavy; } UIImpactFeedbackGenerator *generator = [[UIImpactFeedbackGenerator alloc] initWithStyle:tStyle]; if (@available(iOS 13.0, *)) { [generator impactOccurredWithIntensity:pIntensity]; } else { [generator impactOccurred]; } } -(void)shareWithTitle:(NSString *)pTitle Url:(NSString *)pUrl ResultCallback:(nonnull BoolResultDel)pResultDel { NSMutableArray *sharingItems = [NSMutableArray new]; if (pTitle && pTitle.length > 0) { [sharingItems addObject:pTitle]; } // if (imageDataString && imageDataString.length > 0) // { // NSData *imageData = [[NSData alloc] initWithBase64EncodedString:imageDataString options:0]; // UIImage *image = [[UIImage alloc] initWithData:imageData]; // // [sharingItems addObject:image]; // } if (pUrl && pUrl.length > 0) { NSURL *shareUrl = [NSURL URLWithString:pUrl]; [sharingItems addObject:shareUrl]; } UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:sharingItems applicationActivities:nil]; activityViewController.popoverPresentationController.sourceView = UnityGetGLViewController().view; activityViewController.popoverPresentationController.sourceRect = CGRectMake(UnityGetGLViewController().view.frame.size.width/2, UnityGetGLViewController().view.frame.size.height/4, 0, 0); activityViewController.modalInPopover = YES; //回调 if ([UIDevice currentDevice].systemVersion.floatValue >= 8.0) { // ios8.0 之后用此方法回调 UIActivityViewControllerCompletionWithItemsHandler itemsBlock = ^(UIActivityType __nullable activityType, BOOL completed, NSArray * __nullable returnedItems, NSError * __nullable activityError) { if(pResultDel != NULL) pResultDel(completed); }; activityViewController.completionWithItemsHandler = itemsBlock; } else { // ios8.0 之前用此方法回调 UIActivityViewControllerCompletionHandler handlerBlock = ^(UIActivityType __nullable activityType, BOOL completed) { if(pResultDel != NULL) pResultDel(completed); }; activityViewController.completionHandler = handlerBlock; } [UnityGetGLViewController() presentViewController:activityViewController animated:YES completion:nil]; } @end