Skip to content

Commit

Permalink
Make MushareText support MacCatalyst
Browse files Browse the repository at this point in the history
  • Loading branch information
yanyin1986 committed Dec 13, 2019
1 parent 14d4801 commit 3bbccfe
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 9 deletions.
14 changes: 12 additions & 2 deletions Demo/YYTextDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/* Begin PBXBuildFile section */
601D5F5A239E104B006EB41E /* YYTextEditRubyExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 601D5F59239E104B006EB41E /* YYTextEditRubyExample.swift */; };
6099F0FC23A3237800381814 /* CoreServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6099F0FB23A3237800381814 /* CoreServices.framework */; };
D91054861F3735D20007F224 /* Animated image support.txt in Resources */ = {isa = PBXBuildFile; fileRef = D910547B1F3735D20007F224 /* Animated image support.txt */; };
D91054871F3735D20007F224 /* YYAnimatedImageView.m in Sources */ = {isa = PBXBuildFile; fileRef = D910547D1F3735D20007F224 /* YYAnimatedImageView.m */; };
D91054881F3735D20007F224 /* YYFrameImage.m in Sources */ = {isa = PBXBuildFile; fileRef = D910547F1F3735D20007F224 /* YYFrameImage.m */; };
Expand Down Expand Up @@ -69,7 +70,6 @@
D91055371F3737540007F224 /* CoreText.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D91055361F3737540007F224 /* CoreText.framework */; };
D91055391F37375A0007F224 /* Accelerate.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D91055381F37375A0007F224 /* Accelerate.framework */; };
D910553B1F37375F0007F224 /* ImageIO.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D910553A1F37375F0007F224 /* ImageIO.framework */; };
D910553D1F3737640007F224 /* MobileCoreServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D910553C1F3737640007F224 /* MobileCoreServices.framework */; };
D910553F1F3737670007F224 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D910553E1F3737670007F224 /* SystemConfiguration.framework */; };
D91055411F37376C0007F224 /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = D91055401F37376C0007F224 /* libz.tbd */; };
D94EE9961F37304200F37AD6 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D94EE9941F37304200F37AD6 /* Main.storyboard */; };
Expand All @@ -81,6 +81,8 @@
/* Begin PBXFileReference section */
601D5F58239E104B006EB41E /* YYTextDemo-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "YYTextDemo-Bridging-Header.h"; sourceTree = "<group>"; };
601D5F59239E104B006EB41E /* YYTextEditRubyExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YYTextEditRubyExample.swift; sourceTree = "<group>"; };
6099F0FA23A3234800381814 /* YYTextDemo.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = YYTextDemo.entitlements; sourceTree = "<group>"; };
6099F0FB23A3237800381814 /* CoreServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreServices.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/CoreServices.framework; sourceTree = DEVELOPER_DIR; };
D910547B1F3735D20007F224 /* Animated image support.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "Animated image support.txt"; sourceTree = "<group>"; };
D910547C1F3735D20007F224 /* YYAnimatedImageView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YYAnimatedImageView.h; sourceTree = "<group>"; };
D910547D1F3735D20007F224 /* YYAnimatedImageView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = YYAnimatedImageView.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -214,8 +216,8 @@
files = (
D91055411F37376C0007F224 /* libz.tbd in Frameworks */,
D910553F1F3737670007F224 /* SystemConfiguration.framework in Frameworks */,
D910553D1F3737640007F224 /* MobileCoreServices.framework in Frameworks */,
D910553B1F37375F0007F224 /* ImageIO.framework in Frameworks */,
6099F0FC23A3237800381814 /* CoreServices.framework in Frameworks */,
D91055391F37375A0007F224 /* Accelerate.framework in Frameworks */,
D91055371F3737540007F224 /* CoreText.framework in Frameworks */,
D91055351F37374F0007F224 /* QuartzCore.framework in Frameworks */,
Expand Down Expand Up @@ -378,6 +380,7 @@
D91055311F37374B0007F224 /* Frameworks */ = {
isa = PBXGroup;
children = (
6099F0FB23A3237800381814 /* CoreServices.framework */,
D91055401F37376C0007F224 /* libz.tbd */,
D910553E1F3737670007F224 /* SystemConfiguration.framework */,
D910553C1F3737640007F224 /* MobileCoreServices.framework */,
Expand Down Expand Up @@ -412,6 +415,7 @@
D94EE98D1F37304200F37AD6 /* YYTextDemo */ = {
isa = PBXGroup;
children = (
6099F0FA23A3234800381814 /* YYTextDemo.entitlements */,
D910550F1F37367B0007F224 /* YYTextExample.h */,
D91055101F37367B0007F224 /* YYTextExample.m */,
D91055111F37367B0007F224 /* YYTextExampleHelper.h */,
Expand Down Expand Up @@ -707,13 +711,16 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = YYTextDemo/YYTextDemo.entitlements;
COMPRESS_PNG_FILES = NO;
DERIVE_MACCATALYST_PRODUCT_BUNDLE_IDENTIFIER = YES;
DEVELOPMENT_TEAM = 9HK6LYYN6L;
INFOPLIST_FILE = YYTextDemo/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.ibireme.YYTextDemo;
PRODUCT_NAME = "$(TARGET_NAME)";
STRIP_PNG_TEXT = NO;
SUPPORTS_MACCATALYST = YES;
SWIFT_OBJC_BRIDGING_HEADER = "YYTextDemo/YYTextDemo-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
Expand All @@ -726,13 +733,16 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = YYTextDemo/YYTextDemo.entitlements;
COMPRESS_PNG_FILES = NO;
DERIVE_MACCATALYST_PRODUCT_BUNDLE_IDENTIFIER = YES;
DEVELOPMENT_TEAM = 9HK6LYYN6L;
INFOPLIST_FILE = YYTextDemo/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.ibireme.YYTextDemo;
PRODUCT_NAME = "$(TARGET_NAME)";
STRIP_PNG_TEXT = NO;
SUPPORTS_MACCATALYST = YES;
SWIFT_OBJC_BRIDGING_HEADER = "YYTextDemo/YYTextDemo-Bridging-Header.h";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
Expand Down
14 changes: 8 additions & 6 deletions Demo/YYTextDemo/YYImage/YYImageCoder.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
#import <ImageIO/ImageIO.h>
#import <Accelerate/Accelerate.h>
#import <QuartzCore/QuartzCore.h>
#import <MobileCoreServices/MobileCoreServices.h>
#import <AssetsLibrary/AssetsLibrary.h>
#import <CoreServices/CoreServices.h>
#import <Photos/Photos.h>
#import <objc/runtime.h>
#import <pthread.h>
#import <zlib.h>
Expand Down Expand Up @@ -2778,14 +2778,16 @@ - (void)setYy_isDecodedForDisplay:(BOOL)isDecodedForDisplay {
- (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){
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
PHAssetCreationRequest *request = [PHAssetCreationRequest creationRequestForAsset];

} completionHandler:^(BOOL success, NSError * _Nullable error) {
if (!completionBlock) return;
if (pthread_main_np()) {
completionBlock(assetURL, error);

} else {
dispatch_async(dispatch_get_main_queue(), ^{
completionBlock(assetURL, error);

});
}
}];
Expand Down
10 changes: 10 additions & 0 deletions Demo/YYTextDemo/YYTextDemo.entitlements
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.network.client</key>
<true/>
</dict>
</plist>
4 changes: 3 additions & 1 deletion YYText/YYTextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -2998,10 +2998,12 @@ - (void)_define:(id)sender {
if (string.length == 0) return;
BOOL resign = [self resignFirstResponder];
if (!resign) return;


#if !TARGET_OS_MACCATALYST
UIReferenceLibraryViewController* ref = [[UIReferenceLibraryViewController alloc] initWithTerm:string];
ref.view.backgroundColor = [UIColor whiteColor];
[[self _getRootViewController] presentViewController:ref animated:YES completion:^{}];
#endif
}


Expand Down

0 comments on commit 3bbccfe

Please sign in to comment.