yasirkula / UnityNativeShare

A Unity plugin to natively share files (images, videos, documents, etc.) and/or plain text on Android & iOS
MIT License
890 stars 131 forks source link

Error with sharing #152

Open zeeshanqaswar1221 opened 1 year ago

zeeshanqaswar1221 commented 1 year ago

image

I am using this block of code to share my json file on Ipad. When I am on the main dialogue Only one json file with a name is being appeared and I am also checking the number of files I have in files list while doing this image

But the problem is when I press "Save to Files" It adds an additional file of "text.txt" so as result it saves two files on the drive instead of just my exported json file.

I am confused why is this happening. To test my case what I did was I tried to mail and copy the file and it was not adding any extra files Instead I was getting the only file that I was wanted which is the desired result.

yasirkula commented 1 year ago

Is it possible that the file is renamed to text.txt and the other json file was already there before?

zeeshanqaswar1221 commented 1 year ago

My code is quite straight forward and I personally don't see it happening at the Unity level. I am not sure about whether its happening on the plugin side or not.

yasirkula commented 1 year ago

I've seen entries mentioning the saved file automatically being renamed to text.txt but never seen any entries where text.txt was duplicated. Please delete both text.txt and the other json file and try again.

zeeshanqaswar1221 commented 1 year ago

Can you tell me how can I verify on my side like where it's being renamed to text.txt?

zeeshanqaswar1221 commented 1 year ago

Like I mentioned earlier its only happened when I press "save to folder " in dialogue box besides that if try to copy or save to note in Ipad it shows me one file

yasirkula commented 1 year ago

Can you tell me how can I verify on my side like where it's being renamed to text.txt?

You can verify it by deleting txt and json from the folder and saving to that folder again. If only txt exists, then the file is renamed.

zeeshanqaswar1221 commented 1 year ago

there is only one file in the folder I Debuged the path of file when pressing the AddFile Event in Xcode and its only one call to addFile and one debug

yasirkula commented 1 year ago

What I'm trying to say is, if when you click the "Save to Files" button, you are saving the file to say X folder, then please delete both txt and json from that X folder and try again. I'm suspecting that the json file in the X folder was present there beforehand and that made you think that calling Share function added both a json and a txt file to X folder whereas in reality, it only added a txt file to the X folder.

zeeshanqaswar1221 commented 1 year ago

No! I totally understand your Point when I try to click "Save to Files" button at the time "X Folder " which I am pointing to is totally empty. When you press "Save to Files" it shows me that on top of "2 Items" and the I proceeded to select X folder which is right below the name.

zeeshanqaswar1221 commented 1 year ago

and I only sent one call to Add a file in Unity which I debugged in Xcode and is precisely only one call and the path I use in AddFile() method is exactly the path to JSON file. What I am confused about is where did this "text.txt" file come from When I am not even creating this file. Is this something happening at plugin level?

zeeshanqaswar1221 commented 1 year ago

Thanks after So many hits and trials Inked195060612-08028f65-009a-4ffe-9fd4-58c1f949606d

I removed these two lines and my problem is solved now its not adding any additional text.txt file and It was happening at the plugin level. Between Thanks for your Support.

yasirkula commented 1 year ago

Thank you for letting me know about this. I believe you can use SetCallback without any issues. This must be related to SetSubject only. I'll research some more to see how it can be resolved.

yasirkula commented 1 year ago

Can you change these lines with the following code (you can do that in Xcode by modifying NativeShare.mm for testing purposes) and see if it resolves the issue:

- (id)activityViewController:(UIActivityViewController *)activityViewController itemForActivityType:(NSString *)activityType
{
    return [activityType isEqualToString:@"com.apple.CloudDocsUI.AddToiCloudDrive"] ? nil : [self body];
}

- (NSString *)activityViewController:(UIActivityViewController *)activityViewController subjectForActivityType:(NSString *)activityType
{
    return [activityType isEqualToString:@"com.apple.CloudDocsUI.AddToiCloudDrive"] ? nil : [self subject];
}