Skip to content

Commit

Permalink
[ios] fix(sharing) Fix share target
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelklehr committed Dec 8, 2023
1 parent e164595 commit f96b3d2
Show file tree
Hide file tree
Showing 7 changed files with 160 additions and 43 deletions.
18 changes: 11 additions & 7 deletions ios/App/App.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
/* Begin PBXCopyFilesBuildPhase section */
1899960C29CCBA1B00ABC3E8 /* Embed Foundation Extensions */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
buildActionMask = 12;
dstPath = "";
dstSubfolderSpec = 13;
files = (
Expand Down Expand Up @@ -382,10 +382,10 @@
MARKETING_VERSION = 1.0;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = org.handmadeideas.floccus;
PRODUCT_BUNDLE_IDENTIFIER = "org.handmadeideas.floccus.new-bookmark";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
"PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]" = "March 23 v3";
"PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]" = "March 23 New Bookmark v2";
SKIP_INSTALL = YES;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
Expand Down Expand Up @@ -415,10 +415,10 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks";
MARKETING_VERSION = 1.0;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = org.handmadeideas.floccus;
PRODUCT_BUNDLE_IDENTIFIER = "org.handmadeideas.floccus.new-bookmark";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
"PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]" = "March 23 v3";
"PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]" = "March 23 New Bookmark v2";
SKIP_INSTALL = YES;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
Expand Down Expand Up @@ -546,9 +546,11 @@
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = BW96RCL7W9;
INFOPLIST_FILE = App/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = Floccus;
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.productivity";
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MARKETING_VERSION = 4.17.1;
MARKETING_VERSION = 5.0.0;
OTHER_SWIFT_FLAGS = "$(inherited) \"-D\" \"COCOAPODS\" \"-DDEBUG\"";
PRODUCT_BUNDLE_IDENTIFIER = org.handmadeideas.floccus;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -573,9 +575,11 @@
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = BW96RCL7W9;
INFOPLIST_FILE = App/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = Floccus;
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.productivity";
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MARKETING_VERSION = 4.17.1;
MARKETING_VERSION = 5.0.0;
PRODUCT_BUNDLE_IDENTIFIER = org.handmadeideas.floccus;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down
10 changes: 10 additions & 0 deletions ios/App/App/App.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.application-groups</key>
<array>
<string>group.org.handmadeideas.floccus</string>
</array>
</dict>
</plist>
2 changes: 1 addition & 1 deletion ios/App/App/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
return true
}

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
var success = true
if CAPBridge.handleOpenUrl(url, options) {
Expand Down
4 changes: 4 additions & 0 deletions ios/App/App/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>CFBundleURLName</key>
<string></string>
<key>CFBundleURLSchemes</key>
<array>
<string>org.handmadeideas.floccus</string>
Expand Down
34 changes: 17 additions & 17 deletions ios/App/Floccus New Bookmark/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,6 @@
<dict>
<key>NSExtension</key>
<dict>
<key>NSExtensionActivationRule</key>
<dict>
<key>NSExtensionActivationSupportsFileWithMaxCount</key>
<integer>5</integer>
<key>NSExtensionActivationSupportsImageWithMaxCount</key>
<integer>5</integer>
<key>NSExtensionActivationSupportsMovieWithMaxCount</key>
<integer>5</integer>
<key>NSExtensionActivationSupportsText</key>
<true/>
<key>NSExtensionActivationSupportsWebPageWithMaxCount</key>
<integer>1</integer>
<key>NSExtensionActivationSupportsWebURLWithMaxCount</key>
<integer>1</integer>
<key>NSExtensionActivationUsesStrictMatching</key>
<false/>
</dict>
<key>NSExtensionAttributes</key>
<dict>
<key>NSExtensionActivationRule</key>
Expand All @@ -31,5 +14,22 @@
<key>NSExtensionPointIdentifier</key>
<string>com.apple.share-services</string>
</dict>
<key>NSExtensionActivationRule</key>
<dict>
<key>NSExtensionActivationSupportsFileWithMaxCount</key>
<integer>5</integer>
<key>NSExtensionActivationSupportsImageWithMaxCount</key>
<integer>5</integer>
<key>NSExtensionActivationSupportsMovieWithMaxCount</key>
<integer>5</integer>
<key>NSExtensionActivationSupportsText</key>
<true/>
<key>NSExtensionActivationSupportsWebPageWithMaxCount</key>
<integer>1</integer>
<key>NSExtensionActivationSupportsWebURLWithMaxCount</key>
<integer>1</integer>
<key>NSExtensionActivationUsesStrictMatching</key>
<false/>
</dict>
</dict>
</plist>
35 changes: 17 additions & 18 deletions ios/App/Floccus New Bookmark/ShareViewController.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

//
// ShareViewController.swift
// mindlib
Expand Down Expand Up @@ -51,20 +50,20 @@ class ShareViewController: UIViewController {

let copyFileUrl =
fileManager.containerURL(forSecurityApplicationGroupIdentifier: "group.org.handmadeideas.floccus")!
.absoluteString.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)! + "/" + url!
.absoluteString.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)! + url!
.lastPathComponent.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!
try? Data(contentsOf: url!).write(to: URL(string: copyFileUrl)!)

return copyFileUrl
}

func saveScreenshot(_ image: UIImage) -> String {
func saveScreenshot(_ image: UIImage, _ index: Int) -> String {
let fileManager = FileManager.default

let copyFileUrl =
fileManager.containerURL(forSecurityApplicationGroupIdentifier: "group.org.handmadeideas.floccus")!
.absoluteString.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!
+ "/screenshot.png"
+ "/screenshot_\(index).png"
do {
try image.pngData()?.write(to: URL(string: copyFileUrl)!)
return copyFileUrl
Expand Down Expand Up @@ -118,23 +117,23 @@ class ShareViewController: UIViewController {
return shareItem
}

fileprivate func handleTypeImage(_ attachment: NSItemProvider)
fileprivate func handleTypeImage(_ attachment: NSItemProvider, _ index: Int)
async throws -> ShareItem
{
let data = try await attachment.loadItem(forTypeIdentifier: kUTTypeImage as String, options: nil)

let shareItem: ShareItem = ShareItem()
switch data {
case let image as UIImage:
shareItem.title = "screenshot"
shareItem.type = "image/png"
shareItem.url = self.saveScreenshot(image)
case let url as URL:
shareItem.title = url.lastPathComponent
shareItem.type = "image/" + url.pathExtension.lowercased()
shareItem.url = self.createSharedFileUrl(url)
default:
print("Unexpected image data:", type(of: data))
switch data {
case let image as UIImage:
shareItem.title = "screenshot_\(index)"
shareItem.type = "image/png"
shareItem.url = self.saveScreenshot(image, index)
case let url as URL:
shareItem.title = url.lastPathComponent
shareItem.type = "image/" + url.pathExtension.lowercased()
shareItem.url = self.createSharedFileUrl(url)
default:
print("Unexpected image data:", type(of: data))
}
return shareItem
}
Expand All @@ -150,7 +149,7 @@ class ShareViewController: UIViewController {
of: ShareItem.self,
body: { taskGroup in

for attachment in extensionItem.attachments! {
for (index, attachment) in extensionItem.attachments!.enumerated() {
if attachment.hasItemConformingToTypeIdentifier(kUTTypeURL as String) {
taskGroup.addTask {
return try await self.handleTypeUrl(attachment)
Expand All @@ -165,7 +164,7 @@ class ShareViewController: UIViewController {
}
} else if attachment.hasItemConformingToTypeIdentifier(kUTTypeImage as String) {
taskGroup.addTask {
return try await self.handleTypeImage(attachment)
return try await self.handleTypeImage(attachment, index)
}
}
}
Expand Down
100 changes: 100 additions & 0 deletions ios/App/Podfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
PODS:
- ByteowlsCapacitorOauth2 (4.0.2):
- Capacitor
- OAuthSwift (= 2.2.0)
- Capacitor (5.5.1):
- CapacitorCordova
- CapacitorApp (5.0.6):
- Capacitor
- CapacitorCommunityHttp (1.4.1):
- Capacitor
- CapacitorCordova (5.5.1)
- CapacitorDevice (5.0.6):
- Capacitor
- CapacitorFilesystem (5.1.4):
- Capacitor
- CapacitorNetwork (5.0.6):
- Capacitor
- CapacitorPreferences (5.0.6):
- Capacitor
- CapacitorShare (5.0.6):
- Capacitor
- CapacitorSplashScreen (5.0.6):
- Capacitor
- CordovaPlugins (5.5.1):
- CapacitorCordova
- CordovaPluginsResources (0.0.105)
- OAuthSwift (2.2.0)
- SendIntent (0.0.1):
- Capacitor

DEPENDENCIES:
- "ByteowlsCapacitorOauth2 (from `../../node_modules/@byteowls/capacitor-oauth2`)"
- "Capacitor (from `../../node_modules/@capacitor/ios`)"
- "CapacitorApp (from `../../node_modules/@capacitor/app`)"
- "CapacitorCommunityHttp (from `../../node_modules/@capacitor-community/http`)"
- "CapacitorCordova (from `../../node_modules/@capacitor/ios`)"
- "CapacitorDevice (from `../../node_modules/@capacitor/device`)"
- "CapacitorFilesystem (from `../../node_modules/@capacitor/filesystem`)"
- "CapacitorNetwork (from `../../node_modules/@capacitor/network`)"
- "CapacitorPreferences (from `../../node_modules/@capacitor/preferences`)"
- "CapacitorShare (from `../../node_modules/@capacitor/share`)"
- "CapacitorSplashScreen (from `../../node_modules/@capacitor/splash-screen`)"
- CordovaPlugins (from `../capacitor-cordova-ios-plugins`)
- CordovaPluginsResources (from `../capacitor-cordova-ios-plugins`)
- SendIntent (from `../../node_modules/send-intent`)

SPEC REPOS:
trunk:
- OAuthSwift

EXTERNAL SOURCES:
ByteowlsCapacitorOauth2:
:path: "../../node_modules/@byteowls/capacitor-oauth2"
Capacitor:
:path: "../../node_modules/@capacitor/ios"
CapacitorApp:
:path: "../../node_modules/@capacitor/app"
CapacitorCommunityHttp:
:path: "../../node_modules/@capacitor-community/http"
CapacitorCordova:
:path: "../../node_modules/@capacitor/ios"
CapacitorDevice:
:path: "../../node_modules/@capacitor/device"
CapacitorFilesystem:
:path: "../../node_modules/@capacitor/filesystem"
CapacitorNetwork:
:path: "../../node_modules/@capacitor/network"
CapacitorPreferences:
:path: "../../node_modules/@capacitor/preferences"
CapacitorShare:
:path: "../../node_modules/@capacitor/share"
CapacitorSplashScreen:
:path: "../../node_modules/@capacitor/splash-screen"
CordovaPlugins:
:path: "../capacitor-cordova-ios-plugins"
CordovaPluginsResources:
:path: "../capacitor-cordova-ios-plugins"
SendIntent:
:path: "../../node_modules/send-intent"

SPEC CHECKSUMS:
ByteowlsCapacitorOauth2: 86f9a61aa413119226b12aabc5d03f185e9e1d28
Capacitor: 9da0a2415e3b6098511f8b5ffdb578d91ee79f8f
CapacitorApp: 024e1b1bea5f883d79f6330d309bc441c88ad04a
CapacitorCommunityHttp: 7be90668527ef14ee10d08135b0e00fac9cf8247
CapacitorCordova: e128cc7688c070ca0bfa439898a5f609da8dbcfe
CapacitorDevice: 2c968f98a1ec4d22357418c1521e7ddc46c675e6
CapacitorFilesystem: af704badfbc69f6f8623d9ed313e5490e3723dcb
CapacitorNetwork: d80b3e79bef6ec37640ee2806c19771f07ff2d0c
CapacitorPreferences: f03954bcb0ff09c792909e46bff88e3183c16b10
CapacitorShare: cd41743331cb71d217c029de54b681cbd91e0fcc
CapacitorSplashScreen: 5fa2ab5e46cf5cc530cf16a51c80c7a986579ccd
CordovaPlugins: ed4ad4b471e30dae7a9f57ee30aed67e71f69a3d
CordovaPluginsResources: 1b3992e05cb6336d2850cd77dd5e3054f2f76f96
OAuthSwift: 75efbb5bd9a4b2b71a37bd7e986bf3f55ddd54c6
SendIntent: 0a17b6984c4f27e9dfa56513267ba2c044a5a6c8

PODFILE CHECKSUM: 43c910b75a1189f19703b70db7029424c839ab8a

COCOAPODS: 1.12.0

0 comments on commit f96b3d2

Please sign in to comment.