Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS not working, No data is parse into app #81

Open
AimanKyo97 opened this issue Jan 17, 2024 · 6 comments
Open

iOS not working, No data is parse into app #81

AimanKyo97 opened this issue Jan 17, 2024 · 6 comments

Comments

@AimanKyo97
Copy link

I did follow the documentation but its not working for me in iOS, can help me check what i doing wrong?
The app can launch when being shared but no data is parse in the app.

iOS Device iPhone:
Version: 17.2.1

Xcode Version:
15.1

In info.plis

<key>CFBundleURLTypes</key> <array> <dict> <key>CFBundleURLName</key> <string>XXX</string> <key>CFBundleTypeRole</key> <string>Editor</string> <key>CFBundleURLSchemes</key> <array> <string>ShareMedia-$(PRODUCT_BUNDLE_IDENTIFIER)</string> </array> </dict> </array>

In Podfile

target 'Runner' do
use_frameworks!
use_modular_headers!

flutter_install_all_ios_pods File.dirname(File.realpath(FILE))
# share_handler addition start
target 'Share Extension' do
inherit! :search_paths
pod "share_handler_ios_models", :path => ".symlinks/plugins/share_handler_ios/ios/Models"
end

end

In Folder Share Extension->ShareViewController.swift

import share_handler_ios_models

@available(iOSApplicationExtension 14.0, *)
class ShareViewController: ShareHandlerIosViewController {}

Inside ShareHandlerIosViewController {}

//
// ShareHandlerIosViewController.swift
// Pods
//
// Created by Josh Juncker on 7/7/22.
//

import UIKit
import Social
import MobileCoreServices
import Photos
import Intents
import Contacts

@available(iOS 14.0, *)
@available(iOSApplicationExtension 14.0, *)
open class ShareHandlerIosViewController: UIViewController {
static var hostAppBundleIdentifier = "com.xxx.xxx"
static var appGroupId = "group.com.xxx.xxx"
let sharedKey = "ShareKey"
var sharedText: [String] = []
let imageContentType = UTType.image.identifier
let movieContentType = UTType.movie.identifier
let textContentType = UTType.text.identifier
let urlContentType = UTType.url.identifier
let fileURLType = UTType.fileURL.identifier
let dataContentType = UTType.data.identifier
var sharedAttachments: [SharedAttachment] = []
lazy var userDefaults: UserDefaults = {
return UserDefaults(suiteName: ShareHandlerIosViewController.appGroupId)!
}()

public func loadIds() {
        // loading Share extension App Id
        let shareExtensionAppBundleIdentifier = Bundle.main.bundleIdentifier!;


        // convert ShareExtension id to host app id
        // By default it is remove last part of id after last point
        // For example: com.test.ShareExtension -> com.test
        let lastIndexOfPoint = shareExtensionAppBundleIdentifier.lastIndex(of: ".");
    ShareHandlerIosViewController.hostAppBundleIdentifier = String(shareExtensionAppBundleIdentifier[..<lastIndexOfPoint!]);

        // loading custom AppGroupId from Build Settings or use group.<hostAppBundleIdentifier>
    ShareHandlerIosViewController.appGroupId = (Bundle.main.object(forInfoDictionaryKey: "AppGroupId") as? String) ?? "group.\(ShareHandlerIosViewController.hostAppBundleIdentifier)";
    }

public override func viewDidLoad() {
    super.viewDidLoad();
    
    // load group and app id from build info
            loadIds();
    Task {
        await handleInputItems()
    }
}

public override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
    extensionContext!.completeRequest(returningItems: [], completionHandler: nil)
}

func handleInputItems() async {
    if let content = extensionContext!.inputItems[0] as? NSExtensionItem {
        if let contents = content.attachments {
            for (index, attachment) in (contents).enumerated() {
                do {
                    if attachment.hasItemConformingToTypeIdentifier(imageContentType) {
                        try await handleImages(content: content, attachment: attachment, index: index)
                    } else if attachment.hasItemConformingToTypeIdentifier(movieContentType) {
                        try await handleVideos(content: content, attachment: attachment, index: index)
                    } else if attachment.hasItemConformingToTypeIdentifier(fileURLType){
                        try await handleFiles(content: content, attachment: attachment, index: index)
                    } else if attachment.hasItemConformingToTypeIdentifier(urlContentType) {
                        try await handleUrl(content: content, attachment: attachment, index: index)
                    } else if attachment.hasItemConformingToTypeIdentifier(textContentType) {
                        try await handleText(content: content, attachment: attachment, index: index)
                    } else if attachment.hasItemConformingToTypeIdentifier(dataContentType) {
                        try await handleData(content: content, attachment: attachment, index: index)
                    } else {
                        print("Attachment not handled with registered type identifiers: \(attachment.registeredTypeIdentifiers)")
                    }
                } catch {
                    self.dismissWithError()
                }
                
            }
        }
        redirectToHostApp()
    }
}

public func getNewFileUrl(fileName: String) -> URL {
    let newFileUrl = FileManager.default
        .containerURL(forSecurityApplicationGroupIdentifier: ShareHandlerIosViewController.appGroupId)!
        .appendingPathComponent(fileName)
    return newFileUrl
}

public func handleText (content: NSExtensionItem, attachment: NSItemProvider, index: Int) async throws {
    let data = try await attachment.loadItem(forTypeIdentifier: textContentType, options: nil)
    
    if let item = data as? String {
        sharedText.append(item)
    } else {
        if let d = data as? Data {
            do{
                let contacts = try CNContactVCardSerialization.contacts(with: d)
                for contact in contacts {
                    let data = try CNContactVCardSerialization.data(with: [contact])
                    let str = String(data: data, encoding: .utf8)!
                    sharedText.append(str)
                }
            } catch {
                dismissWithError()
            }
        } else {
            dismissWithError()
        }
    }
} 

public func handleUrl (content: NSExtensionItem, attachment: NSItemProvider, index: Int) async throws {
    let data = try await attachment.loadItem(forTypeIdentifier: urlContentType, options: nil)
    
        if let item = data as? URL {
            sharedText.append(item.absoluteString)
        } else {
            dismissWithError()
        }
    
}

public func handleImages (content: NSExtensionItem, attachment: NSItemProvider, index: Int) async throws {
    let data = try await attachment.loadItem(forTypeIdentifier: imageContentType, options: nil)
        
    var fileName: String?
    var imageData: Data?
    var sourceUrl: URL?
    if let url = data as? URL {
        fileName = getFileName(from: url, type: .image)
        sourceUrl = url
    } else if let iData = data as? Data {
        fileName = UUID().uuidString + ".png"
        imageData = iData
    } else if let image = data as? UIImage {
        fileName = UUID().uuidString + ".png"
        imageData = image.pngData()
    }
    
    if let _fileName = fileName {
        let newFileUrl = getNewFileUrl(fileName: _fileName)
        do {
            if FileManager.default.fileExists(atPath: newFileUrl.path) {
                try FileManager.default.removeItem(at: newFileUrl)
            }
        } catch {
            print("Error removing item")
        }
        
        
        var copied: Bool = false
        if let _data = imageData {
            copied = FileManager.default.createFile(atPath: newFileUrl.path, contents: _data)
        } else if let _sourceUrl = sourceUrl {
            copied = copyFile(at: _sourceUrl, to: newFileUrl)
        }
        
        if (copied) {
            sharedAttachments.append(SharedAttachment.init(path:  newFileUrl.absoluteString, type: .image))
        } else {
            dismissWithError()
            return
        }
        
    } else {
        dismissWithError()
        return
    }
    
}

public func handleVideos (content: NSExtensionItem, attachment: NSItemProvider, index: Int) async throws {
    let data = try await attachment.loadItem(forTypeIdentifier: movieContentType, options: nil)
     
        
    if let url = data as? URL {
        
        // Always copy
        let fileName = getFileName(from: url, type: .video)
        let newFileUrl = getNewFileUrl(fileName: fileName)
        let copied = copyFile(at: url, to: newFileUrl)
        if(copied) {
            sharedAttachments.append(SharedAttachment.init(path:  newFileUrl.absoluteString, type: .video))
        }
    } else {
        dismissWithError()
    }
    
}

public func handleFiles (content: NSExtensionItem, attachment: NSItemProvider, index: Int) async throws {
    let data = try await attachment.loadItem(forTypeIdentifier: fileURLType, options: nil)
     
    if let url = data as? URL {
        
        // Always copy
        let fileName = getFileName(from :url, type: .file)
        let newFileUrl = getNewFileUrl(fileName: fileName)
        let copied = copyFile(at: url, to: newFileUrl)
        if (copied) {
            sharedAttachments.append(SharedAttachment.init(path:  newFileUrl.absoluteString, type: .file))
        }
    } else {
        dismissWithError()
    }
    
}

public func handleData (content: NSExtensionItem, attachment: NSItemProvider, index: Int) async throws {
    let data = try await attachment.loadItem(forTypeIdentifier: dataContentType, options: nil)
     
    if let url = data as? URL {
        
        // Always copy
        let fileName = getFileName(from :url, type: .file)
        let newFileUrl = getNewFileUrl(fileName: fileName)
        let copied = copyFile(at: url, to: newFileUrl)
        if (copied) {
            sharedAttachments.append(SharedAttachment.init(path:  newFileUrl.absoluteString, type: .file))
        }
    } else {
        dismissWithError()
    }
    
}

public func dismissWithError() {
    print("[ERROR] Error loading data!")
    let alert = UIAlertController(title: "Error", message: "Error loading data", preferredStyle: .alert)
    
    let action = UIAlertAction(title: "Error", style: .cancel) { _ in
        self.dismiss(animated: true, completion: nil)
    }
    
    alert.addAction(action)
    present(alert, animated: true, completion: nil)
    extensionContext!.completeRequest(returningItems: [], completionHandler: nil)
}

public func redirectToHostApp() {
    // ids may not loaded yet so we need loadIds here too
    loadIds();
    let url = URL(string: "ShareMedia-\(ShareHandlerIosViewController.hostAppBundleIdentifier)://\(ShareHandlerIosViewController.hostAppBundleIdentifier)?key=\(sharedKey)")
    var responder = self as UIResponder?
    let selectorOpenURL = sel_registerName("openURL:")
    
    let intent = self.extensionContext?.intent as? INSendMessageIntent
    
    let conversationIdentifier = intent?.conversationIdentifier
    let sender = intent?.sender
    let serviceName = intent?.serviceName
    let speakableGroupName = intent?.speakableGroupName
    
    let sharedMedia = SharedMedia.init(attachments: sharedAttachments, conversationIdentifier: conversationIdentifier, content: sharedText.joined(separator: "\n"), speakableGroupName: speakableGroupName?.spokenPhrase, serviceName: serviceName, senderIdentifier: sender?.contactIdentifier ?? sender?.customIdentifier, imageFilePath: nil)
    
    let json = sharedMedia.toJson()
    
    userDefaults.set(json, forKey: sharedKey)
    userDefaults.synchronize()
    
    while (responder != nil) {
        if (responder?.responds(to: selectorOpenURL))! {
            let _ = responder?.perform(selectorOpenURL, with: url)
        }
        responder = responder!.next
    }
}

enum RedirectType {
    case media
    case text
    case file
}

func getExtension(from url: URL, type: SharedAttachmentType) -> String {
    let parts = url.lastPathComponent.components(separatedBy: ".")
    var ex: String? = nil
    if (parts.count > 1) {
        ex = parts.last
    }
    
    if (ex == nil) {
        switch type {
        case .image:
            ex = "PNG"
        case .video:
            ex = "MP4"
        case .file:
            ex = "TXT"
        default:
            ex = ""
        }
    }
    return ex ?? "Unknown"
}

func getFileName(from url: URL, type: SharedAttachmentType) -> String {
    var name = url.lastPathComponent
    
    if (name.isEmpty) {
        name = UUID().uuidString + "." + getExtension(from: url, type: type)
    }
    
    return name
}

func copyFile(at srcURL: URL, to dstURL: URL) -> Bool {
    do {
        if FileManager.default.fileExists(atPath: dstURL.path) {
            try FileManager.default.removeItem(at: dstURL)
        }
        try FileManager.default.copyItem(at: srcURL, to: dstURL)
    } catch (let error) {
        print("Cannot copy item at \(srcURL) to \(dstURL): \(error)")
        return false
    }
    return true
}

}`

Screenshot at Jan 17 09-42-54 Screenshot at Jan 17 10-14-16 Screenshot at Jan 17 09-46-34 Screenshot at Jan 17 09-49-56 Screenshot at Jan 17 09-55-10

Part 1 cycle:
Screenshot at Jan 17 10-00-00
Part 2 cycle:
Screenshot at Jan 17 10-00-42

Screenshot at Jan 17 10-08-37

@JoshJuncker @czredhat @sidlatau @daviddomkar @martingeorgiu

Thank you in advanced.

@simranKa
Copy link

By making these changes I am able to get data in IOS:

  1. In ShareHandlerIosViewController -> loadIds() -> Replace ShareHandlerIosViewController.hostAppBundleIdentifier with your app bundle identifier and ShareHandlerIosViewController.appGroupId with your appGroupId

Screenshot 2024-01-17 at 10 40 52 AM
In Runner -> Build Phase reorder the list also work to get IOS app in share tray.

@AimanKyo97
Copy link
Author

By making these changes I am able to get data in IOS:

  1. In ShareHandlerIosViewController -> loadIds() -> Replace ShareHandlerIosViewController.hostAppBundleIdentifier with your app bundle identifier and ShareHandlerIosViewController.appGroupId with your appGroupId

Screenshot 2024-01-17 at 10 40 52 AM In Runner -> Build Phase reorder the list also work to get IOS app in share tray.

@simranKa I have try it but the data i receive still null, below is example code i used in ShareHandlerIosViewController, and Build Phases in my project

//
// ShareHandlerIosViewController.swift
// Pods
//
// Created by Josh Juncker on 7/7/22.
//

import UIKit
import Social
import MobileCoreServices
import Photos
import Intents
import Contacts

@available(iOS 14.0, *)
@available(iOSApplicationExtension 14.0, *)
open class ShareHandlerIosViewController: UIViewController {
static var hostAppBundleIdentifier = "com.xxx.xxx”
static var appGroupId = "group.com.xxx.xxx”
let sharedKey = "ShareKey"
var sharedText: [String] = []
let imageContentType = UTType.image.identifier
let movieContentType = UTType.movie.identifier
let textContentType = UTType.text.identifier
let urlContentType = UTType.url.identifier
let fileURLType = UTType.fileURL.identifier
let dataContentType = UTType.data.identifier
var sharedAttachments: [SharedAttachment] = []
lazy var userDefaults: UserDefaults = {
return UserDefaults(suiteName: ShareHandlerIosViewController.appGroupId)!
}()

public func loadIds() {
        // loading Share extension App Id
        let shareExtensionAppBundleIdentifier = Bundle.main.bundleIdentifier!;


        // convert ShareExtension id to host app id
        // By default it is remove last part of id after last point
        // For example: com.test.ShareExtension -> com.test
        let lastIndexOfPoint = shareExtensionAppBundleIdentifier.lastIndex(of: ".");
    ShareHandlerIosViewController.hostAppBundleIdentifier = "com.xxx.xxx";

        // loading custom AppGroupId from Build Settings or use group.<hostAppBundleIdentifier>
    ShareHandlerIosViewController.appGroupId = "group.com.xxx.xxx”;
    }

public override func viewDidLoad() {
    super.viewDidLoad();
    
    // load group and app id from build info
            loadIds();
    Task {
        await handleInputItems()
    }
}

public override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
    extensionContext!.completeRequest(returningItems: [], completionHandler: nil)
}

func handleInputItems() async {
    if let content = extensionContext!.inputItems[0] as? NSExtensionItem {
        if let contents = content.attachments {
            for (index, attachment) in (contents).enumerated() {
                do {
                    if attachment.hasItemConformingToTypeIdentifier(imageContentType) {
                        try await handleImages(content: content, attachment: attachment, index: index)
                    } else if attachment.hasItemConformingToTypeIdentifier(movieContentType) {
                        try await handleVideos(content: content, attachment: attachment, index: index)
                    } else if attachment.hasItemConformingToTypeIdentifier(fileURLType){
                        try await handleFiles(content: content, attachment: attachment, index: index)
                    } else if attachment.hasItemConformingToTypeIdentifier(urlContentType) {
                        try await handleUrl(content: content, attachment: attachment, index: index)
                    } else if attachment.hasItemConformingToTypeIdentifier(textContentType) {
                        try await handleText(content: content, attachment: attachment, index: index)
                    } else if attachment.hasItemConformingToTypeIdentifier(dataContentType) {
                        try await handleData(content: content, attachment: attachment, index: index)
                    } else {
                        print("Attachment not handled with registered type identifiers: \(attachment.registeredTypeIdentifiers)")
                    }
                } catch {
                    self.dismissWithError()
                }
                
            }
        }
        redirectToHostApp()
    }
}

public func getNewFileUrl(fileName: String) -> URL {
    let newFileUrl = FileManager.default
        .containerURL(forSecurityApplicationGroupIdentifier: ShareHandlerIosViewController.appGroupId)!
        .appendingPathComponent(fileName)
    return newFileUrl
}

public func handleText (content: NSExtensionItem, attachment: NSItemProvider, index: Int) async throws {
    let data = try await attachment.loadItem(forTypeIdentifier: textContentType, options: nil)
    
    if let item = data as? String {
        sharedText.append(item)
    } else {
        if let d = data as? Data {
            do{
                let contacts = try CNContactVCardSerialization.contacts(with: d)
                for contact in contacts {
                    let data = try CNContactVCardSerialization.data(with: [contact])
                    let str = String(data: data, encoding: .utf8)!
                    sharedText.append(str)
                }
            } catch {
                dismissWithError()
            }
        } else {
            dismissWithError()
        }
    }
} 

public func handleUrl (content: NSExtensionItem, attachment: NSItemProvider, index: Int) async throws {
    let data = try await attachment.loadItem(forTypeIdentifier: urlContentType, options: nil)
    
        if let item = data as? URL {
            sharedText.append(item.absoluteString)
        } else {
            dismissWithError()
        }
    
}

public func handleImages (content: NSExtensionItem, attachment: NSItemProvider, index: Int) async throws {
    let data = try await attachment.loadItem(forTypeIdentifier: imageContentType, options: nil)
        
    var fileName: String?
    var imageData: Data?
    var sourceUrl: URL?
    if let url = data as? URL {
        fileName = getFileName(from: url, type: .image)
        sourceUrl = url
    } else if let iData = data as? Data {
        fileName = UUID().uuidString + ".png"
        imageData = iData
    } else if let image = data as? UIImage {
        fileName = UUID().uuidString + ".png"
        imageData = image.pngData()
    }
    
    if let _fileName = fileName {
        let newFileUrl = getNewFileUrl(fileName: _fileName)
        do {
            if FileManager.default.fileExists(atPath: newFileUrl.path) {
                try FileManager.default.removeItem(at: newFileUrl)
            }
        } catch {
            print("Error removing item")
        }
        
        
        var copied: Bool = false
        if let _data = imageData {
            copied = FileManager.default.createFile(atPath: newFileUrl.path, contents: _data)
        } else if let _sourceUrl = sourceUrl {
            copied = copyFile(at: _sourceUrl, to: newFileUrl)
        }
        
        if (copied) {
            sharedAttachments.append(SharedAttachment.init(path:  newFileUrl.absoluteString, type: .image))
        } else {
            dismissWithError()
            return
        }
        
    } else {
        dismissWithError()
        return
    }
    
}

public func handleVideos (content: NSExtensionItem, attachment: NSItemProvider, index: Int) async throws {
    let data = try await attachment.loadItem(forTypeIdentifier: movieContentType, options: nil)
     
        
    if let url = data as? URL {
        
        // Always copy
        let fileName = getFileName(from: url, type: .video)
        let newFileUrl = getNewFileUrl(fileName: fileName)
        let copied = copyFile(at: url, to: newFileUrl)
        if(copied) {
            sharedAttachments.append(SharedAttachment.init(path:  newFileUrl.absoluteString, type: .video))
        }
    } else {
        dismissWithError()
    }
    
}

public func handleFiles (content: NSExtensionItem, attachment: NSItemProvider, index: Int) async throws {
    let data = try await attachment.loadItem(forTypeIdentifier: fileURLType, options: nil)
     
    if let url = data as? URL {
        
        // Always copy
        let fileName = getFileName(from :url, type: .file)
        let newFileUrl = getNewFileUrl(fileName: fileName)
        let copied = copyFile(at: url, to: newFileUrl)
        if (copied) {
            sharedAttachments.append(SharedAttachment.init(path:  newFileUrl.absoluteString, type: .file))
        }
    } else {
        dismissWithError()
    }
    
}

public func handleData (content: NSExtensionItem, attachment: NSItemProvider, index: Int) async throws {
    let data = try await attachment.loadItem(forTypeIdentifier: dataContentType, options: nil)
     
    if let url = data as? URL {
        
        // Always copy
        let fileName = getFileName(from :url, type: .file)
        let newFileUrl = getNewFileUrl(fileName: fileName)
        let copied = copyFile(at: url, to: newFileUrl)
        if (copied) {
            sharedAttachments.append(SharedAttachment.init(path:  newFileUrl.absoluteString, type: .file))
        }
    } else {
        dismissWithError()
    }
    
}

public func dismissWithError() {
    print("[ERROR] Error loading data!")
    let alert = UIAlertController(title: "Error", message: "Error loading data", preferredStyle: .alert)
    
    let action = UIAlertAction(title: "Error", style: .cancel) { _ in
        self.dismiss(animated: true, completion: nil)
    }
    
    alert.addAction(action)
    present(alert, animated: true, completion: nil)
    extensionContext!.completeRequest(returningItems: [], completionHandler: nil)
}

public func redirectToHostApp() {
    // ids may not loaded yet so we need loadIds here too
    loadIds();
    let url = URL(string: "ShareMedia-com.xxx.xxx://com.xxx.xxx?key=\(sharedKey)")
    var responder = self as UIResponder?
    let selectorOpenURL = sel_registerName("openURL:")
    
    let intent = self.extensionContext?.intent as? INSendMessageIntent
    
    let conversationIdentifier = intent?.conversationIdentifier
    let sender = intent?.sender
    let serviceName = intent?.serviceName
    let speakableGroupName = intent?.speakableGroupName
    
    let sharedMedia = SharedMedia.init(attachments: sharedAttachments, conversationIdentifier: conversationIdentifier, content: sharedText.joined(separator: "\n"), speakableGroupName: speakableGroupName?.spokenPhrase, serviceName: serviceName, senderIdentifier: sender?.contactIdentifier ?? sender?.customIdentifier, imageFilePath: nil)
    
    let json = sharedMedia.toJson()
    
    userDefaults.set(json, forKey: sharedKey)
    userDefaults.synchronize()
    
    while (responder != nil) {
        if (responder?.responds(to: selectorOpenURL))! {
            let _ = responder?.perform(selectorOpenURL, with: url)
        }
        responder = responder!.next
    }
}

enum RedirectType {
    case media
    case text
    case file
}

func getExtension(from url: URL, type: SharedAttachmentType) -> String {
    let parts = url.lastPathComponent.components(separatedBy: ".")
    var ex: String? = nil
    if (parts.count > 1) {
        ex = parts.last
    }
    
    if (ex == nil) {
        switch type {
        case .image:
            ex = "PNG"
        case .video:
            ex = "MP4"
        case .file:
            ex = "TXT"
        default:
            ex = ""
        }
    }
    return ex ?? "Unknown"
}

func getFileName(from url: URL, type: SharedAttachmentType) -> String {
    var name = url.lastPathComponent
    
    if (name.isEmpty) {
        name = UUID().uuidString + "." + getExtension(from: url, type: type)
    }
    
    return name
}

func copyFile(at srcURL: URL, to dstURL: URL) -> Bool {
    do {
        if FileManager.default.fileExists(atPath: dstURL.path) {
            try FileManager.default.removeItem(at: dstURL)
        }
        try FileManager.default.copyItem(at: srcURL, to: dstURL)
    } catch (let error) {
        print("Cannot copy item at \(srcURL) to \(dstURL): \(error)")
        return false
    }
    return true
}

}

Build phases :

Screenshot at Jan 17 15-49-43

Below is my record video:

WhatsApp.Video.2024-01-17.at.16.03.59.mp4

Is there something i missing? Thank you @simranKa

@aniketcodebase
Copy link

AimanKyo97

  • were you able to get it to work?
  • It is working for me in a test project that I created back in November with
    share_handler: 0.0.19
    share_handler_ios: 0.0.12
    share_handler_android: 0.0.7
    share_handler_platform_interface: 0.0.6
  • But not working in another project created in January with same dependencies. Currenty, I am using XCode 15.2
  • I think it is colliding with something

@arrrrny
Copy link

arrrrny commented Mar 16, 2024

@aniketcodebase It has nothing to do with the loadIds,
The build phase order is crucial, I was getting circular dependency error, so follow @simranKa on that, strangely when I compared the ShareExtension entitlements file with my project and the example project(which works fine). I realized Xcode added Wifi capability as well. I removed that. and also on the URL Schemes, make sure it is "ShareMedia-$(PRODUCT_BUNDLE_IDENTIFIER)" Initially I made it something custom so that might be the issue as well. Happy hacking

Screenshot 2024-03-16 at 10 46 20 PM

@aniketcodebase
Copy link

in my case, actual problem was a mismatch (case sensitive) between the group-id (autogenerated after enabling the app-groups ) and bundle id

  • Bundle Id: some.something.myTestApp
  • group id: group.some.something.mytestapp

I had to correct my group-id to group.some.something.myTestApp

  • ShareHandlerIosViewController's loadId() does the magic and my bundle-id and group-id were not matching here in loadId()

@arrrrny
Copy link

arrrrny commented Sep 22, 2024

@AimanKyo97 I explained step by step how to setup fo Xcode 16 and IOS 18, the example app works right out the box by following instructions here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants