Skip to content

Commit

Permalink
Enable backward compatibility down to iOS 8.
Browse files Browse the repository at this point in the history
  • Loading branch information
KasemJaffer committed Jan 26, 2024
1 parent 4dde174 commit 0e47986
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 13 deletions.
6 changes: 3 additions & 3 deletions example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.kasem.sharing;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
VERSIONING_SYSTEM = "apple-generic";
};
name = Profile;
Expand Down Expand Up @@ -819,7 +819,7 @@
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
VERSIONING_SYSTEM = "apple-generic";
};
name = Debug;
Expand Down Expand Up @@ -858,7 +858,7 @@
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
VERSIONING_SYSTEM = "apple-generic";
};
name = Release;
Expand Down
2 changes: 1 addition & 1 deletion example/ios/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import receive_sharing_intent
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
Expand Down
24 changes: 16 additions & 8 deletions ios/Classes/RSIShareViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Social
import MobileCoreServices
import Photos

@available(swift, introduced: 5.0)
open class RSIShareViewController: SLComposeServiceViewController {
var hostAppBundleIdentifier = ""
var appGroupId = ""
Expand All @@ -31,7 +32,7 @@ open class RSIShareViewController: SLComposeServiceViewController {

// This is called after the user selects Post. Do the upload of contentText and/or NSExtensionContext attachments.
if let content = extensionContext!.inputItems[0] as? NSExtensionItem {
if let contents = content.attachments as? [NSItemProvider] {
if let contents = content.attachments {
for (index, attachment) in (contents).enumerated() {
for type in SharedMediaType.allCases {
if attachment.hasItemConformingToTypeIdentifier(type.toUTTypeIdentifier) {
Expand Down Expand Up @@ -214,8 +215,8 @@ open class RSIShareViewController: SLComposeServiceViewController {
// let scale = UIScreen.main.scale
assetImgGenerate.maximumSize = CGSize(width: 360, height: 360)
do {
let img = try assetImgGenerate.copyCGImage(at: CMTimeMakeWithSeconds(600, Int32(1.0)), actualTime: nil)
try UIImagePNGRepresentation(UIImage(cgImage: img))?.write(to: thumbnailPath)
let img = try assetImgGenerate.copyCGImage(at: CMTimeMakeWithSeconds(600, preferredTimescale: 1), actualTime: nil)
try UIImage(cgImage: img).pngData()?.write(to: thumbnailPath)
saved = true
} catch {
saved = false
Expand All @@ -240,11 +241,18 @@ open class RSIShareViewController: SLComposeServiceViewController {

extension URL {
public func mimeType() -> String {
if let mimeType = UTType(filenameExtension: self.pathExtension)?.preferredMIMEType {
return mimeType
}
else {
return "application/octet-stream"
if #available(iOS 14.0, *) {
if let mimeType = UTType(filenameExtension: self.pathExtension)?.preferredMIMEType {
return mimeType
}
} else {
if let uti = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, self.pathExtension as NSString, nil)?.takeRetainedValue() {
if let mimetype = UTTypeCopyPreferredTagWithClass(uti, kUTTagClassMIMEType)?.takeRetainedValue() {
return mimetype as String
}
}
}

return "application/octet-stream"
}
}
16 changes: 16 additions & 0 deletions ios/Classes/SwiftReceiveSharingIntentPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,22 @@ public enum SharedMediaType: String, Codable, CaseIterable {
case url

public var toUTTypeIdentifier: String {
if #available(iOS 14.0, *) {
switch self {
case .image:
return UTType.image.identifier
case .video:
return UTType.movie.identifier
case .text:
return UTType.text.identifier
// case .audio:
// return UTType.audio.identifier
case .file:
return UTType.fileURL.identifier
case .url:
return UTType.url.identifier
}
}
switch self {
case .image:
return "public.image"
Expand Down
2 changes: 1 addition & 1 deletion ios/receive_sharing_intent.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
Pod::Spec.new do |s|
s.name = 'receive_sharing_intent'
s.version = '1.6.1'
s.version = '1.6.2'
s.summary = 'A flutter plugin that enables flutter apps to receive sharing photos from other apps.'
s.description = <<-DESC
A flutter plugin that enables flutter apps to receive sharing photos from other apps.
Expand Down

0 comments on commit 0e47986

Please sign in to comment.