Skip to content

Commit

Permalink
Merge pull request #8 from AboutShout/airdrop
Browse files Browse the repository at this point in the history
Completes #7 Initial working airdrop handling support.
  • Loading branch information
JoshJuncker authored Jun 2, 2022
2 parents 27e89db + ed2b8bd commit f80e751
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 19 deletions.
2 changes: 2 additions & 0 deletions share_handler/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# 0.0.5
Added support for handling airdropped files
# 0.0.4
Fix for channel sometimes receiving full SharedMedia object rather than map
# 0.0.3
Expand Down
22 changes: 21 additions & 1 deletion share_handler/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,31 @@ First, add `share_handler` as a [dependency in your pubspec.yaml file](https://f
<string>ShareMedia-$(PRODUCT_BUNDLE_IDENTIFIER)</string>
</array>
</dict>
<dict/>
</array>

<key>NSPhotoLibraryUsageDescription</key>
<string>Photos can be shared to and used in this app</string>

<!-- Optional: Add/Customize for AirDrop support -->
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeName</key>
<string>ShareHandler</string>
<key>LSHandlerRank</key>
<string>Alternate</string>
<key>LSItemContentTypes</key>
<array>
<string>public.file-url</string>
<string>public.image</string>
<string>public.text</string>
<string>public.movie</string>
<string>public.url</string>
<string>public.data</string>
</array>
</dict>
</array>

<!-- Add for share_handler end -->
```

Expand Down
4 changes: 2 additions & 2 deletions share_handler/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: share_handler
description: A Flutter plugin to handle incoming shared text/media, as well as add share to suggestions/shortcuts.
repository: https://github.com/AboutShout/share_handler/tree/main/share_handler
version: 0.0.4
version: 0.0.5

environment:
sdk: ">=2.14.0 <3.0.0"
Expand Down Expand Up @@ -29,7 +29,7 @@ dependencies:
share_handler_android: ^0.0.4
# share_handler_android:
# path: ../share_handler_android
share_handler_ios: ^0.0.4
share_handler_ios: ^0.0.5
# share_handler_ios:
# path: ../share_handler_ios
# share_handler_linux:
Expand Down
2 changes: 2 additions & 0 deletions share_handler_ios/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# 0.0.5
Added support for handling airdropped files
# 0.0.4
Fix for channel sometimes receiving full SharedMedia object rather than map
# 0.0.3
Expand Down
37 changes: 22 additions & 15 deletions share_handler_ios/ios/Classes/SwiftShareHandlerIosPlatform.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class SwiftShareHandlerIosPlatform: NSObject, FlutterPlugin, FlutterStrea
// - found the issue while developing multiple applications using this library, after "application(_:open:options:)" is called, the first app using this librabry (first app by bundle id alphabetically) is opened
public func hasMatchingSchemePrefix(url: URL?) -> Bool {
if let url = url, let appDomain = Bundle.main.bundleIdentifier {
return url.absoluteString.hasPrefix("\(self.customSchemePrefix)-\(appDomain)")
return url.absoluteString.hasPrefix("\(self.customSchemePrefix)-\(appDomain)") || url.absoluteString.hasPrefix("file://")
}
return false
}
Expand Down Expand Up @@ -116,26 +116,33 @@ public class SwiftShareHandlerIosPlatform: NSObject, FlutterPlugin, FlutterStrea
// let appDomain = Bundle.main.bundleIdentifier!
let appGroupId = (Bundle.main.object(forInfoDictionaryKey: "AppGroupId") as? String) ?? "group.\(Bundle.main.bundleIdentifier!)"
let userDefaults = UserDefaults(suiteName: appGroupId)

var sharedMedia: SharedMedia?

let params = url.queryDictionary
if let sharedPreferencesKey = params?["key"] {
if let data = userDefaults?.object(forKey: sharedPreferencesKey) as? Data {

if let sharedMedia = try? JSONDecoder().decode(SharedMedia.self, from: data) {
sharedMedia.attachments?.forEach {$0.path = getAbsolutePath(for: $0.path) ?? $0.path}
latestMedia = sharedMedia
if (setInitialData) {
initialMedia = sharedMedia
}
let map = sharedMedia.toDictionary()
eventSink?(map)
}



return true
sharedMedia = try? JSONDecoder().decode(SharedMedia.self, from: data)
}
} else if url.absoluteString.hasPrefix("file://") {
sharedMedia = SharedMedia.init(attachments: [SharedAttachment.init(path: url.absoluteString, type: SharedAttachmentType.file)], conversationIdentifier: nil, content: nil, speakableGroupName: nil, serviceName: nil, senderIdentifier: nil, imageFilePath: nil)
}

if let media = sharedMedia {
media.attachments?.forEach {$0.path = getAbsolutePath(for: $0.path) ?? $0.path}
latestMedia = media
if (setInitialData) {
initialMedia = media
}
let map = media.toDictionary()
eventSink?(map)

return true
}





// if url.fragment == "media" {
// if let key = url.host?.components(separatedBy: "=").last,
Expand Down
2 changes: 1 addition & 1 deletion share_handler_ios/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: share_handler_ios
description: An implementation for the iOS platform of the Flutter share_handler plugin.
repository: https://github.com/AboutShout/share_handler/tree/main/share_handler_ios
version: 0.0.4
version: 0.0.5

environment:
sdk: ">=2.14.0 <3.0.0"
Expand Down

0 comments on commit f80e751

Please sign in to comment.