IOS Share extension not visible in share sheet

I have an iOS application which can get launched when user taps a file with .csk extension. Basically, I’ve associated my app with that extension. If multiple .csk files are selected (by clicking the ‘…’ at the top right of Files app) and shared, in the share sheet, my app appears, and when its chosen, only the first file is passed as a parameter to onOpenUrl(perform:). This is evident from the fact that the onOpenURL(perform:) provides only one URL as the parameter.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>WindowGroup {
FileContentView()
.onOpenURL(perform: { (fileUrl: URL) in // Only one URL can be delivered here
Log(String(format: "File Url = %@", fileUrl.absoluteString))
})
}
</code>
<code>WindowGroup { FileContentView() .onOpenURL(perform: { (fileUrl: URL) in // Only one URL can be delivered here Log(String(format: "File Url = %@", fileUrl.absoluteString)) }) } </code>
WindowGroup {
    FileContentView()
        .onOpenURL(perform: { (fileUrl: URL) in  // Only one URL can be delivered here                     

            Log(String(format: "File Url = %@", fileUrl.absoluteString))    
        })
}

onOpenURL(perform:) is the SwiftUI way to obtain the url with which the app was launched. In UIKit, the URLs are delivered to scene(_:openURLContexts:). If UIKit app is launched with multiple files, only the first file is provided despite scene(_:openURLContexts:) providing an array of URLs. This is also confirmed by an Apple frameworks engineer here.

An alternate way to accept multiple files is to use a Share extension, as described in this stackoverflow post. I created a ShareExtension and removed the default SLComposeServiceViewController, as I want to completely customize the UI (as described in this stackoverflow post). I’ve defined a custom ViewController as follows (consisting of only log statements as of now):

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>class ShareViewController: UIViewController {
override func viewDidLoad() {
log("ShareViewController.viewDidLoad()")
guard let extensionItem: NSExtensionItem = extensionContext?.inputItems.first as? NSExtensionItem,
let data: [AnyHashable:Any] = extensionItem.userInfo else {
log("Error in obtaining data!")
return
}
log("data = " + String(describing: data))
}
override func viewDidAppear(_ animated: Bool) {
log("ShareViewController.viewDidApper(_:)")
}
override func viewDidDisappear(_ animated: Bool) {
log("ShareViewController.viewDidDisappear(_:)")
}
deinit {
log("ShareViewController.deinit()")
}
}
</code>
<code>class ShareViewController: UIViewController { override func viewDidLoad() { log("ShareViewController.viewDidLoad()") guard let extensionItem: NSExtensionItem = extensionContext?.inputItems.first as? NSExtensionItem, let data: [AnyHashable:Any] = extensionItem.userInfo else { log("Error in obtaining data!") return } log("data = " + String(describing: data)) } override func viewDidAppear(_ animated: Bool) { log("ShareViewController.viewDidApper(_:)") } override func viewDidDisappear(_ animated: Bool) { log("ShareViewController.viewDidDisappear(_:)") } deinit { log("ShareViewController.deinit()") } } </code>
class ShareViewController: UIViewController {
    
    override func viewDidLoad() {
        log("ShareViewController.viewDidLoad()")
        
        guard let extensionItem: NSExtensionItem = extensionContext?.inputItems.first as? NSExtensionItem,
        let data: [AnyHashable:Any] = extensionItem.userInfo else {
            log("Error in obtaining data!")
            return
        }
        
        log("data = " + String(describing: data))
    }
    
    override func viewDidAppear(_ animated: Bool) {
        log("ShareViewController.viewDidApper(_:)")
    }
    
    override func viewDidDisappear(_ animated: Bool) {
        log("ShareViewController.viewDidDisappear(_:)")
    }
    
    deinit {
        log("ShareViewController.deinit()")
    }
}

Now, I need to specify the activation rules i.e., my ShareExtension should be shown in share sheet only when a .csk file is selected.
I have the following info.plist file:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code><dict>
<key>NSExtension</key>
<dict>
<key>NSExtensionAttributes</key>
<dict>
<key>NSSExtensionActivationRule</key>
<dict>
<key>NSExtensionActivationSupportsFileWithMaxCount</key>
<integer>5</integer>
</dict>
</dict>
<key>NSExtensionPrincipalClass</key>
<string>$(PRODUCT_MODULE_NAME).ShareViewController</string>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.share-services</string>
</dict>
</dict>
</plist>
</code>
<code><dict> <key>NSExtension</key> <dict> <key>NSExtensionAttributes</key> <dict> <key>NSSExtensionActivationRule</key> <dict> <key>NSExtensionActivationSupportsFileWithMaxCount</key> <integer>5</integer> </dict> </dict> <key>NSExtensionPrincipalClass</key> <string>$(PRODUCT_MODULE_NAME).ShareViewController</string> <key>NSExtensionPointIdentifier</key> <string>com.apple.share-services</string> </dict> </dict> </plist> </code>
<dict>
    <key>NSExtension</key>
    <dict>
        <key>NSExtensionAttributes</key>
        <dict>
            <key>NSSExtensionActivationRule</key>
            <dict>
                <key>NSExtensionActivationSupportsFileWithMaxCount</key>
                <integer>5</integer>
            </dict>
        </dict>
        <key>NSExtensionPrincipalClass</key>
        <string>$(PRODUCT_MODULE_NAME).ShareViewController</string>
        <key>NSExtensionPointIdentifier</key>
        <string>com.apple.share-services</string>
    </dict>
</dict>
</plist>

I expect my app to launch when upto 5 files of any extension are selected and shared. By I never see my app extension. If I chose 5 .csk files, I can see my app, but not my app extension.

So, two issues:

  1. What else is required in the plist file to show my ShareExtension in the share sheet?
  2. After 1 is resolved, I only need my ShareExtension to get launched when a .csk file is selected. How can I achieve this? I’ve used UIExportedTypesDeclaration and CFBundleDocumentTypes to associate my app with .csk file, but how to associate my ShareExtension with this particular file type?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật