瀏覽代碼

【VisionPro适配】适配VisionOS

xcbosa mbp16 1 年之前
父節點
當前提交
a1eb600012
共有 4 個文件被更改,包括 42 次插入14 次删除
  1. 1 1
      YYImage.podspec
  2. 11 1
      YYImage/YYFrameImage.m
  3. 8 0
      YYImage/YYImage.m
  4. 22 12
      YYImage/YYImageCoder.m

+ 1 - 1
YYImage.podspec

@@ -17,7 +17,7 @@ Pod::Spec.new do |s|
     core.source_files = 'YYImage/*.{h,m}'
     core.public_header_files = 'YYImage/*.{h}'
     core.libraries = 'z'
-    core.frameworks = 'UIKit', 'CoreFoundation', 'QuartzCore', 'AssetsLibrary', 'ImageIO', 'Accelerate', 'MobileCoreServices'
+    core.frameworks = 'UIKit', 'CoreFoundation', 'QuartzCore', 'ImageIO', 'Accelerate', 'MobileCoreServices'
   end
   
   s.subspec 'WebP' do |webp|

+ 11 - 1
YYImage/YYFrameImage.m

@@ -92,7 +92,11 @@ static CGFloat _NSStringPathScale(NSString *string) {
     if (dataArray.count != frameDurations.count) return nil;
     
     NSData *firstData = dataArray[0];
+#if TARGET_OS_VISION
+    CGFloat scale = 1.f;
+#else
     CGFloat scale = [UIScreen mainScreen].scale;
+#endif
     UIImage *firstCG = [[[UIImage alloc] initWithData:firstData] yy_imageByDecoded];
     self = [self initWithCGImage:firstCG.CGImage scale:scale orientation:UIImageOrientationUp];
     if (!self) return nil;
@@ -135,7 +139,13 @@ static CGFloat _NSStringPathScale(NSString *string) {
     } else if (_imageDatas) {
         if (index >= _imageDatas.count) return nil;
         NSData *data = _imageDatas[index];
-        return [[UIImage imageWithData:data scale:[UIScreen mainScreen].scale] yy_imageByDecoded];
+        return [[UIImage imageWithData:data scale:
+#if TARGET_OS_VISION
+                 1.f
+#else
+                 [UIScreen mainScreen].scale
+#endif
+                ] yy_imageByDecoded];
     } else {
         return index == 0 ? self : nil;
     }

+ 8 - 0
YYImage/YYImage.m

@@ -16,6 +16,9 @@
  e.g. iPhone3GS:@[@1,@2,@3] iPhone5:@[@2,@3,@1]  iPhone6 Plus:@[@3,@2,@1]
  */
 static NSArray *_NSBundlePreferredScales() {
+#if TARGET_OS_VISION
+    return @[@1, @2, @3];
+#else
     static NSArray *scales;
     static dispatch_once_t onceToken;
     dispatch_once(&onceToken, ^{
@@ -29,6 +32,7 @@ static NSArray *_NSBundlePreferredScales() {
         }
     });
     return scales;
+#endif
 }
 
 /**
@@ -143,7 +147,11 @@ static CGFloat _NSStringPathScale(NSString *string) {
 
 - (instancetype)initWithData:(NSData *)data scale:(CGFloat)scale {
     if (data.length == 0) return nil;
+#if TARGET_OS_VISION
+    if (scale <= 0) scale = 1.f;
+#else
     if (scale <= 0) scale = [UIScreen mainScreen].scale;
+#endif
     _preloadedLock = dispatch_semaphore_create(1);
     @autoreleasepool {
         YYImageDecoder *decoder = [YYImageDecoder decoderWithData:data scale:scale];

+ 22 - 12
YYImage/YYImageCoder.m

@@ -16,7 +16,11 @@
 #import <Accelerate/Accelerate.h>
 #import <QuartzCore/QuartzCore.h>
 #import <MobileCoreServices/MobileCoreServices.h>
-#import <AssetsLibrary/AssetsLibrary.h>
+
+#if !TARGET_OS_VISION
+//#import <AssetsLibrary/AssetsLibrary.h>
+#endif
+
 #import <objc/runtime.h>
 #import <pthread.h>
 #import <zlib.h>
@@ -1542,7 +1546,11 @@ CGImageRef YYCGImageCreateWithWebPData(CFDataRef webpData,
 }
 
 - (instancetype)init {
+#if !TARGET_OS_VISION
     return [self initWithScale:[UIScreen mainScreen].scale];
+#else
+    return [self initWithScale:1.f];
+#endif
 }
 
 - (instancetype)initWithScale:(CGFloat)scale {
@@ -2795,17 +2803,19 @@ CGImageRef YYCGImageCreateWithWebPData(CFDataRef webpData,
 - (void)yy_saveToAlbumWithCompletionBlock:(void(^)(NSURL *assetURL, NSError *error))completionBlock {
     dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
         NSData *data = [self _yy_dataRepresentationForSystem:YES];
-        ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
-        [library writeImageDataToSavedPhotosAlbum:data metadata:nil completionBlock:^(NSURL *assetURL, NSError *error){
-            if (!completionBlock) return;
-            if (pthread_main_np()) {
-                completionBlock(assetURL, error);
-            } else {
-                dispatch_async(dispatch_get_main_queue(), ^{
-                    completionBlock(assetURL, error);
-                });
-            }
-        }];
+//#if !TARGET_OS_VISION
+//        ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
+//        [library writeImageDataToSavedPhotosAlbum:data metadata:nil completionBlock:^(NSURL *assetURL, NSError *error){
+//            if (!completionBlock) return;
+//            if (pthread_main_np()) {
+//                completionBlock(assetURL, error);
+//            } else {
+//                dispatch_async(dispatch_get_main_queue(), ^{
+//                    completionBlock(assetURL, error);
+//                });
+//            }
+//        }];
+//#endif
     });
 }