Skip to content

Commit b6fc96c

Browse files
Wrap analysis
1 parent 1e5744c commit b6fc96c

File tree

5 files changed

+78
-5
lines changed

5 files changed

+78
-5
lines changed

BFRImageViewController/BFRImageContainerViewController.m

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@
1010
#import "BFRBackLoadedImageSource.h"
1111
#import "BFRImageViewerDownloadProgressView.h"
1212
#import "BFRImageViewerConstants.h"
13+
#import "BFRImageViewer-Swift.h"
1314
#import <Photos/Photos.h>
1415
#import <PhotosUI/PhotosUI.h>
1516
#import <PINRemoteImage/PINAnimatedImageView.h>
1617
#import <PINRemoteImage/PINRemoteImage.h>
1718
#import <PINRemoteImage/PINImageView+PINRemoteImage.h>
1819

20+
API_AVAILABLE(ios(16.0))
1921
@interface BFRImageContainerViewController () <UIScrollViewDelegate, UIGestureRecognizerDelegate>
2022

2123
/*! This is responsible for panning and zooming the images. */
@@ -48,6 +50,8 @@ @interface BFRImageContainerViewController () <UIScrollViewDelegate, UIGestureRe
4850
/*! Currently, this only shows if a live photo is displayed to avoid gesture recognizer conflicts with playback and sharing. */
4951
@property (strong, nonatomic, nullable) UIBarButtonItem *shareBarButtonItem;
5052

53+
@property (strong, nonatomic, nullable) LiveTextManager *liveTextManager API_AVAILABLE(ios(16));
54+
5155
@end
5256

5357
@implementation BFRImageContainerViewController
@@ -229,6 +233,7 @@ - (void)createActiveAssetView {
229233
}
230234
[resizableImageView addGestureRecognizer:panImg];
231235

236+
// Live Photo Autoplay
232237
if (self.assetType == BFRImageAssetTypeLivePhoto) {
233238
self.livePhotoImgView = (PHLivePhotoView *)resizableImageView;
234239

@@ -238,6 +243,16 @@ - (void)createActiveAssetView {
238243
} else {
239244
self.imgView = (PINAnimatedImageView *)resizableImageView;
240245
}
246+
247+
// Live Text
248+
if (@available(iOS 16.0, *)) {
249+
if ([LiveTextManager isLiveTextAvailable] && self.assetType == BFRImageAssetTypeImage) {
250+
self.liveTextManager = [LiveTextManager new];
251+
[self.liveTextManager analyzeImageViewWithView:self.imgView image:(UIImage *)self.imgSrc completionHandler:^{
252+
253+
}];
254+
}
255+
}
241256
}
242257

243258
- (void)addImageToScrollView {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
//
2+
// Use this file to import your target's public headers that you would like to expose to Swift.
3+
//
4+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//
2+
// LiveTextManager.swift
3+
// BFRImageViewer
4+
//
5+
// Created by Jordan Morgan on 7/12/22.
6+
// Copyright © 2022 Andrew Yates. All rights reserved.
7+
//
8+
9+
import Foundation
10+
import VisionKit
11+
12+
@available(iOS 16.0, *)
13+
@objc @MainActor class LiveTextManager: NSObject {
14+
private var interaction = ImageAnalysisInteraction()
15+
16+
@objc
17+
static func isLiveTextAvailable() -> Bool {
18+
return ImageAnalyzer.isSupported
19+
}
20+
21+
@objc
22+
func analyzeImageView(view: UIView, image: UIImage) async {
23+
interaction = ImageAnalysisInteraction()
24+
interaction.preferredInteractionTypes = .automatic
25+
view.addInteraction(interaction)
26+
27+
let configuration = ImageAnalyzer.Configuration([.text, .machineReadableCode])
28+
let analyzer = ImageAnalyzer()
29+
let analysis = try? await analyzer.analyze(image, configuration: configuration)
30+
interaction.analysis = analysis
31+
}
32+
}

BFRImageViewer.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Pod::Spec.new do |s|
1717
s.source_files = 'Classes', 'BFRImageViewController/**/*.{h,m}'
1818
s.resources = ['BFRImageViewController/**/BFRImageViewerLocalizations.bundle']
1919
s.exclude_files = 'BFRImageViewController/**/lowResImage.png'
20-
s.platform = :ios, '13.0'
20+
s.platform = :ios, '14.0'
2121
s.requires_arc = true
2222
s.frameworks = "UIKit", "Photos"
2323
s.dependency 'PINRemoteImage/iOS', '~> 3.0.0'

BFRImageViewerDemo/BFRImageViewer.xcodeproj/project.pbxproj

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
1797CB8E1E81BB4F00D9F729 /* BFRImageTransitionAnimator.m in Sources */ = {isa = PBXBuildFile; fileRef = 1797CB8D1E81BB4F00D9F729 /* BFRImageTransitionAnimator.m */; };
1515
1797CB911E81BBB200D9F729 /* ThirdViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 1797CB901E81BBB200D9F729 /* ThirdViewController.m */; };
1616
17C1AAB61D9D6EBF00FF1B67 /* BFRImageViewerLocalizations.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 17C1AAB51D9D6EBF00FF1B67 /* BFRImageViewerLocalizations.bundle */; };
17+
333CCA39287DC15B004EF4A5 /* LiveTextManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 333CCA38287DC15B004EF4A5 /* LiveTextManager.swift */; };
1718
33625B75264D71130003310C /* lowResImage.png in Resources */ = {isa = PBXBuildFile; fileRef = 33625B74264D71130003310C /* lowResImage.png */; };
1819
3D65F036BBCC181E7FD291F7 /* libPods-BFRImageViewer.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 76763DB871F085556628E1C6 /* libPods-BFRImageViewer.a */; };
1920
944B4DB01BFFC0C000B9BF87 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 944B4DAF1BFFC0C000B9BF87 /* main.m */; };
@@ -42,6 +43,8 @@
4243
1797CB901E81BBB200D9F729 /* ThirdViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ThirdViewController.m; sourceTree = "<group>"; };
4344
17C1AAB51D9D6EBF00FF1B67 /* BFRImageViewerLocalizations.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = BFRImageViewerLocalizations.bundle; sourceTree = "<group>"; };
4445
17C1AAB91D9D702E00FF1B67 /* BFRImageViewerLocalizations.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BFRImageViewerLocalizations.h; sourceTree = "<group>"; };
46+
333CCA37287DC15A004EF4A5 /* BFRImageViewer-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "BFRImageViewer-Bridging-Header.h"; sourceTree = "<group>"; };
47+
333CCA38287DC15B004EF4A5 /* LiveTextManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LiveTextManager.swift; sourceTree = "<group>"; };
4548
33625B74264D71130003310C /* lowResImage.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = lowResImage.png; sourceTree = "<group>"; };
4649
3C46F30D2C78F64E6BC23C87 /* Pods-BFRImageViewer.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-BFRImageViewer.debug.xcconfig"; path = "Pods/Target Support Files/Pods-BFRImageViewer/Pods-BFRImageViewer.debug.xcconfig"; sourceTree = "<group>"; };
4750
76763DB871F085556628E1C6 /* libPods-BFRImageViewer.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-BFRImageViewer.a"; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -75,6 +78,15 @@
7578
/* End PBXFrameworksBuildPhase section */
7679

7780
/* Begin PBXGroup section */
81+
333CCA36287DC147004EF4A5 /* Live Text */ = {
82+
isa = PBXGroup;
83+
children = (
84+
333CCA38287DC15B004EF4A5 /* LiveTextManager.swift */,
85+
333CCA37287DC15A004EF4A5 /* BFRImageViewer-Bridging-Header.h */,
86+
);
87+
path = "Live Text";
88+
sourceTree = "<group>";
89+
};
7890
5191CE176EA32C80E7D64558 /* Frameworks */ = {
7991
isa = PBXGroup;
8092
children = (
@@ -144,6 +156,7 @@
144156
944B4DE41BFFC0E300B9BF87 /* BFRImageViewController */ = {
145157
isa = PBXGroup;
146158
children = (
159+
333CCA36287DC147004EF4A5 /* Live Text */,
147160
578DFD551CB6E7F400BFBD00 /* Resources */,
148161
944B4DE51BFFC0E300B9BF87 /* BFRImageContainerViewController.h */,
149162
944B4DE61BFFC0E300B9BF87 /* BFRImageContainerViewController.m */,
@@ -205,6 +218,7 @@
205218
944B4DAA1BFFC0C000B9BF87 = {
206219
CreatedOnToolsVersion = 7.1.1;
207220
DevelopmentTeam = UYDA63C4EC;
221+
LastSwiftMigration = 1400;
208222
};
209223
};
210224
};
@@ -277,6 +291,7 @@
277291
1702C69A1F86BBFC00104D0B /* BFRImageViewerConstants.m in Sources */,
278292
944B4DE91BFFC0E300B9BF87 /* BFRImageContainerViewController.m in Sources */,
279293
944B4DB61BFFC0C000B9BF87 /* FirstViewController.m in Sources */,
294+
333CCA39287DC15B004EF4A5 /* LiveTextManager.swift in Sources */,
280295
944B4DB01BFFC0C000B9BF87 /* main.m in Sources */,
281296
);
282297
runOnlyForDeploymentPostprocessing = 0;
@@ -343,7 +358,7 @@
343358
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
344359
GCC_WARN_UNUSED_FUNCTION = YES;
345360
GCC_WARN_UNUSED_VARIABLE = YES;
346-
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
361+
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
347362
MTL_ENABLE_DEBUG_INFO = YES;
348363
ONLY_ACTIVE_ARCH = YES;
349364
SDKROOT = iphoneos;
@@ -393,7 +408,7 @@
393408
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
394409
GCC_WARN_UNUSED_FUNCTION = YES;
395410
GCC_WARN_UNUSED_VARIABLE = YES;
396-
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
411+
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
397412
MTL_ENABLE_DEBUG_INFO = NO;
398413
SDKROOT = iphoneos;
399414
TARGETED_DEVICE_FAMILY = "1,2";
@@ -406,12 +421,16 @@
406421
baseConfigurationReference = 3C46F30D2C78F64E6BC23C87 /* Pods-BFRImageViewer.debug.xcconfig */;
407422
buildSettings = {
408423
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
424+
CLANG_ENABLE_MODULES = YES;
409425
DEVELOPMENT_TEAM = UYDA63C4EC;
410426
INFOPLIST_FILE = BFRImageViewer/Info.plist;
411-
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
427+
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
412428
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
413429
PRODUCT_BUNDLE_IDENTIFIER = com.buffer.BFRImageViewer;
414430
PRODUCT_NAME = "$(TARGET_NAME)";
431+
SWIFT_OBJC_BRIDGING_HEADER = "../BFRImageViewController/Live Text/BFRImageViewer-Bridging-Header.h";
432+
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
433+
SWIFT_VERSION = 5.0;
415434
};
416435
name = Debug;
417436
};
@@ -420,12 +439,15 @@
420439
baseConfigurationReference = 1264A436520DEA8753316972 /* Pods-BFRImageViewer.release.xcconfig */;
421440
buildSettings = {
422441
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
442+
CLANG_ENABLE_MODULES = YES;
423443
DEVELOPMENT_TEAM = UYDA63C4EC;
424444
INFOPLIST_FILE = BFRImageViewer/Info.plist;
425-
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
445+
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
426446
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
427447
PRODUCT_BUNDLE_IDENTIFIER = com.buffer.BFRImageViewer;
428448
PRODUCT_NAME = "$(TARGET_NAME)";
449+
SWIFT_OBJC_BRIDGING_HEADER = "../BFRImageViewController/Live Text/BFRImageViewer-Bridging-Header.h";
450+
SWIFT_VERSION = 5.0;
429451
};
430452
name = Release;
431453
};

0 commit comments

Comments
 (0)