TF-523: handle file and open app form ios/android native
This commit is contained in:
@@ -90,6 +90,29 @@
|
|||||||
<data android:mimeType="image/*" />
|
<data android:mimeType="image/*" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.SEND" />
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
<data android:mimeType="video/*" />
|
||||||
|
</intent-filter>
|
||||||
|
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.SEND_MULTIPLE" />
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
<data android:mimeType="video/*" />
|
||||||
|
</intent-filter>
|
||||||
|
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.SEND" />
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
<data android:mimeType="*/*" />
|
||||||
|
</intent-filter>
|
||||||
|
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.SEND_MULTIPLE" />
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
<data android:mimeType="*/*" />
|
||||||
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<provider
|
<provider
|
||||||
|
|||||||
@@ -46,8 +46,8 @@
|
|||||||
<string>https</string>
|
<string>https</string>
|
||||||
<string>http</string>
|
<string>http</string>
|
||||||
<string>mailto</string>
|
<string>mailto</string>
|
||||||
<string>sms</string>
|
<string>sms</string>
|
||||||
<string>tel</string>
|
<string>tel</string>
|
||||||
</array>
|
</array>
|
||||||
<key>LSRequiresIPhoneOS</key>
|
<key>LSRequiresIPhoneOS</key>
|
||||||
<true/>
|
<true/>
|
||||||
|
|||||||
@@ -26,6 +26,10 @@
|
|||||||
<dict>
|
<dict>
|
||||||
<key>NSExtensionActivationRule</key>
|
<key>NSExtensionActivationRule</key>
|
||||||
<dict>
|
<dict>
|
||||||
|
<key>NSExtensionActivationSupportsFileWithMaxCount</key>
|
||||||
|
<integer>15</integer>
|
||||||
|
<key>NSExtensionActivationSupportsMovieWithMaxCount</key>
|
||||||
|
<integer>15</integer>
|
||||||
<key>NSExtensionActivationSupportsImageWithMaxCount</key>
|
<key>NSExtensionActivationSupportsImageWithMaxCount</key>
|
||||||
<integer>15</integer>
|
<integer>15</integer>
|
||||||
<key>NSExtensionActivationSupportsText</key>
|
<key>NSExtensionActivationSupportsText</key>
|
||||||
@@ -35,6 +39,7 @@
|
|||||||
</dict>
|
</dict>
|
||||||
<key>PHSupportedMediaTypes</key>
|
<key>PHSupportedMediaTypes</key>
|
||||||
<array>
|
<array>
|
||||||
|
<string>Video</string>
|
||||||
<string>Image</string>
|
<string>Image</string>
|
||||||
</array>
|
</array>
|
||||||
</dict>
|
</dict>
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ class ShareViewController: SLComposeServiceViewController {
|
|||||||
let imageContentType = kUTTypeImage as String
|
let imageContentType = kUTTypeImage as String
|
||||||
let textContentType = kUTTypeText as String
|
let textContentType = kUTTypeText as String
|
||||||
let urlContentType = kUTTypeURL as String
|
let urlContentType = kUTTypeURL as String
|
||||||
|
let videoContentType = kUTTypeMovie as String
|
||||||
|
let fileURLType = kUTTypeFileURL as String
|
||||||
|
|
||||||
override func isContentValid() -> Bool {
|
override func isContentValid() -> Bool {
|
||||||
return true
|
return true
|
||||||
@@ -50,6 +52,10 @@ class ShareViewController: SLComposeServiceViewController {
|
|||||||
handleText(content: content, attachment: attachment, index: index)
|
handleText(content: content, attachment: attachment, index: index)
|
||||||
} else if attachment.hasItemConformingToTypeIdentifier(urlContentType) {
|
} else if attachment.hasItemConformingToTypeIdentifier(urlContentType) {
|
||||||
handleUrl(content: content, attachment: attachment, index: index)
|
handleUrl(content: content, attachment: attachment, index: index)
|
||||||
|
} else if attachment.hasItemConformingToTypeIdentifier(fileURLType) {
|
||||||
|
handleFiles(content: content, attachment: attachment, index: index)
|
||||||
|
} else if attachment.hasItemConformingToTypeIdentifier(videoContentType) {
|
||||||
|
handleVideos(content: content, attachment: attachment, index: index)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -135,6 +141,66 @@ class ShareViewController: SLComposeServiceViewController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func handleVideos (content: NSExtensionItem, attachment: NSItemProvider, index: Int) {
|
||||||
|
attachment.loadItem(forTypeIdentifier: videoContentType, options: nil) { [weak self] data, error in
|
||||||
|
|
||||||
|
if error == nil, let url = data as? URL, let this = self {
|
||||||
|
|
||||||
|
// Always copy
|
||||||
|
let fileName = this.getFileName(from: url, type: .video)
|
||||||
|
let newPath = FileManager.default
|
||||||
|
.containerURL(forSecurityApplicationGroupIdentifier: this.appGroupId)!
|
||||||
|
.appendingPathComponent(fileName)
|
||||||
|
let copied = this.copyFile(at: url, to: newPath)
|
||||||
|
if(copied) {
|
||||||
|
guard let sharedFile = this.getSharedMediaFile(forVideo: newPath) else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.sharedMedia.append(sharedFile)
|
||||||
|
}
|
||||||
|
|
||||||
|
// If this is the last item, save imagesData in userDefaults and redirect to host app
|
||||||
|
if index == (content.attachments?.count)! - 1 {
|
||||||
|
let userDefaults = UserDefaults(suiteName: this.appGroupId)
|
||||||
|
userDefaults?.set(this.toData(data: this.sharedMedia), forKey: this.sharedKey)
|
||||||
|
userDefaults?.synchronize()
|
||||||
|
this.redirectToHostApp(type: .media)
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
self?.dismissWithError()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func handleFiles (content: NSExtensionItem, attachment: NSItemProvider, index: Int) {
|
||||||
|
attachment.loadItem(forTypeIdentifier: fileURLType, options: nil) { [weak self] data, error in
|
||||||
|
|
||||||
|
if error == nil, let url = data as? URL, let this = self {
|
||||||
|
|
||||||
|
// Always copy
|
||||||
|
let fileName = this.getFileName(from :url, type: .file)
|
||||||
|
let newPath = FileManager.default
|
||||||
|
.containerURL(forSecurityApplicationGroupIdentifier: this.appGroupId)!
|
||||||
|
.appendingPathComponent(fileName)
|
||||||
|
let copied = this.copyFile(at: url, to: newPath)
|
||||||
|
if (copied) {
|
||||||
|
this.sharedMedia.append(SharedMediaFile(path: newPath.absoluteString, thumbnail: nil, duration: nil, type: .file))
|
||||||
|
}
|
||||||
|
|
||||||
|
if index == (content.attachments?.count)! - 1 {
|
||||||
|
let userDefaults = UserDefaults(suiteName: this.appGroupId)
|
||||||
|
userDefaults?.set(this.toData(data: this.sharedMedia), forKey: this.sharedKey)
|
||||||
|
userDefaults?.synchronize()
|
||||||
|
this.redirectToHostApp(type: .file)
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
self?.dismissWithError()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private func dismissWithError() {
|
private func dismissWithError() {
|
||||||
|
|||||||
Reference in New Issue
Block a user