Share Files on iOS between different Apps












3















I want to create a reusable class library for different apps on iOS let's call them:




  • com.developer1.appname (App1)

  • com.developer2.appname (App2)


My first goal is to let them share some data.
App1 creates some data and saves the information.
App2 loads the data and uses it for further processing.



I already read ways to share on ios and found somewhere that it could be possible to write my object data into images or contacts.



Right now, I'm facing the approach of the General Pasteboard.
However, after approx. one hour my object can not be found anymore in the pasteboard (altough it should be persistent see )



Code for storing into the pasteboard:



partial void Testbutton_TouchUpInside(UIButton sender)
{
var pasteboard = UIPasteboard.General;

//Create Data
// 4 * 1 MB
IEnumerable<int> idata = Enumerable.Range(0, 1024);
int iarray = idata.ToArray();
byte data = new byte[1+iarray.Length * sizeof(int)];
Buffer.BlockCopy(iarray, 0, data, 1, data.Length-1);
data[0] = counter++;

NSData nsd = NSData.FromArray(data);

// insert to pasteboard
//pasteboard.SetData(nsd, "mydata");

// nach etwa 1h ist es weg
pasteboard.SetItemProviders(new NSItemProvider {new NSItemProvider(nsd, key)},false,NSDate.DistantFuture);


testlabel.Text = "Inserted Data to Pasteboard";
}


code for reading item:



partial void Testbutton2_TouchUpInside(UIButton sender)
{
var pasteboard = UIPasteboard.General;
bool contains = pasteboard.Contains(new { key });
if(contains)
{
testlabel2.Text = $"Contains {key}";

var data = pasteboard.DataForPasteboardType(key);
var dataBytes = new byte[data.Length];
System.Runtime.InteropServices.Marshal.Copy(data.Bytes, dataBytes, 0, Convert.ToInt32(data.Length));

int ints = new int[(dataBytes.Length-1)/4];
Buffer.BlockCopy(dataBytes, 1, ints, 0, dataBytes.Length - 1);
testlabel.Text = "Loaded " + dataBytes.Length + " bytes";
//testlabel2.Text += "Data = {"+dataBytes[0]+","+String.Join(", ", ints) +"}";

StringBuilder sb = new StringBuilder(1024 );
sb.Append("Data = {" + dataBytes[0]);
foreach (var i1 in ints)
{
sb.Append($", {i1.ToString()}");
}
testlabel2.Text = sb.ToString() + "}";
int i = 123;
}
else
{
testlabel2.Text = $"Contains NOT {key}";
}
}


Can someone tell me what why the object is beeing deleted in this case, or what would be a nice way to share objects (typically bytearrays) between two apps from different developers.
Thanks in advance.










share|improve this question


















  • 1





    Pasteboard is for the user to control not an app. If the user selects Copy and Paste that's fine but the app should not do it without user interaction

    – Neil
    Nov 21 '18 at 9:43











  • Thanks for your reply, what approach would you suggest to share files properly between different apps (from different developers/teams). CustomURLscheme might work but then App2 asks for data and App1 gets to foreground. After that App1 has to call an URL for App2 to get App2 back into foreground.

    – alexdie01
    Nov 21 '18 at 9:50


















3















I want to create a reusable class library for different apps on iOS let's call them:




  • com.developer1.appname (App1)

  • com.developer2.appname (App2)


My first goal is to let them share some data.
App1 creates some data and saves the information.
App2 loads the data and uses it for further processing.



I already read ways to share on ios and found somewhere that it could be possible to write my object data into images or contacts.



Right now, I'm facing the approach of the General Pasteboard.
However, after approx. one hour my object can not be found anymore in the pasteboard (altough it should be persistent see )



Code for storing into the pasteboard:



partial void Testbutton_TouchUpInside(UIButton sender)
{
var pasteboard = UIPasteboard.General;

//Create Data
// 4 * 1 MB
IEnumerable<int> idata = Enumerable.Range(0, 1024);
int iarray = idata.ToArray();
byte data = new byte[1+iarray.Length * sizeof(int)];
Buffer.BlockCopy(iarray, 0, data, 1, data.Length-1);
data[0] = counter++;

NSData nsd = NSData.FromArray(data);

// insert to pasteboard
//pasteboard.SetData(nsd, "mydata");

// nach etwa 1h ist es weg
pasteboard.SetItemProviders(new NSItemProvider {new NSItemProvider(nsd, key)},false,NSDate.DistantFuture);


testlabel.Text = "Inserted Data to Pasteboard";
}


code for reading item:



partial void Testbutton2_TouchUpInside(UIButton sender)
{
var pasteboard = UIPasteboard.General;
bool contains = pasteboard.Contains(new { key });
if(contains)
{
testlabel2.Text = $"Contains {key}";

var data = pasteboard.DataForPasteboardType(key);
var dataBytes = new byte[data.Length];
System.Runtime.InteropServices.Marshal.Copy(data.Bytes, dataBytes, 0, Convert.ToInt32(data.Length));

int ints = new int[(dataBytes.Length-1)/4];
Buffer.BlockCopy(dataBytes, 1, ints, 0, dataBytes.Length - 1);
testlabel.Text = "Loaded " + dataBytes.Length + " bytes";
//testlabel2.Text += "Data = {"+dataBytes[0]+","+String.Join(", ", ints) +"}";

StringBuilder sb = new StringBuilder(1024 );
sb.Append("Data = {" + dataBytes[0]);
foreach (var i1 in ints)
{
sb.Append($", {i1.ToString()}");
}
testlabel2.Text = sb.ToString() + "}";
int i = 123;
}
else
{
testlabel2.Text = $"Contains NOT {key}";
}
}


Can someone tell me what why the object is beeing deleted in this case, or what would be a nice way to share objects (typically bytearrays) between two apps from different developers.
Thanks in advance.










share|improve this question


















  • 1





    Pasteboard is for the user to control not an app. If the user selects Copy and Paste that's fine but the app should not do it without user interaction

    – Neil
    Nov 21 '18 at 9:43











  • Thanks for your reply, what approach would you suggest to share files properly between different apps (from different developers/teams). CustomURLscheme might work but then App2 asks for data and App1 gets to foreground. After that App1 has to call an URL for App2 to get App2 back into foreground.

    – alexdie01
    Nov 21 '18 at 9:50
















3












3








3








I want to create a reusable class library for different apps on iOS let's call them:




  • com.developer1.appname (App1)

  • com.developer2.appname (App2)


My first goal is to let them share some data.
App1 creates some data and saves the information.
App2 loads the data and uses it for further processing.



I already read ways to share on ios and found somewhere that it could be possible to write my object data into images or contacts.



Right now, I'm facing the approach of the General Pasteboard.
However, after approx. one hour my object can not be found anymore in the pasteboard (altough it should be persistent see )



Code for storing into the pasteboard:



partial void Testbutton_TouchUpInside(UIButton sender)
{
var pasteboard = UIPasteboard.General;

//Create Data
// 4 * 1 MB
IEnumerable<int> idata = Enumerable.Range(0, 1024);
int iarray = idata.ToArray();
byte data = new byte[1+iarray.Length * sizeof(int)];
Buffer.BlockCopy(iarray, 0, data, 1, data.Length-1);
data[0] = counter++;

NSData nsd = NSData.FromArray(data);

// insert to pasteboard
//pasteboard.SetData(nsd, "mydata");

// nach etwa 1h ist es weg
pasteboard.SetItemProviders(new NSItemProvider {new NSItemProvider(nsd, key)},false,NSDate.DistantFuture);


testlabel.Text = "Inserted Data to Pasteboard";
}


code for reading item:



partial void Testbutton2_TouchUpInside(UIButton sender)
{
var pasteboard = UIPasteboard.General;
bool contains = pasteboard.Contains(new { key });
if(contains)
{
testlabel2.Text = $"Contains {key}";

var data = pasteboard.DataForPasteboardType(key);
var dataBytes = new byte[data.Length];
System.Runtime.InteropServices.Marshal.Copy(data.Bytes, dataBytes, 0, Convert.ToInt32(data.Length));

int ints = new int[(dataBytes.Length-1)/4];
Buffer.BlockCopy(dataBytes, 1, ints, 0, dataBytes.Length - 1);
testlabel.Text = "Loaded " + dataBytes.Length + " bytes";
//testlabel2.Text += "Data = {"+dataBytes[0]+","+String.Join(", ", ints) +"}";

StringBuilder sb = new StringBuilder(1024 );
sb.Append("Data = {" + dataBytes[0]);
foreach (var i1 in ints)
{
sb.Append($", {i1.ToString()}");
}
testlabel2.Text = sb.ToString() + "}";
int i = 123;
}
else
{
testlabel2.Text = $"Contains NOT {key}";
}
}


Can someone tell me what why the object is beeing deleted in this case, or what would be a nice way to share objects (typically bytearrays) between two apps from different developers.
Thanks in advance.










share|improve this question














I want to create a reusable class library for different apps on iOS let's call them:




  • com.developer1.appname (App1)

  • com.developer2.appname (App2)


My first goal is to let them share some data.
App1 creates some data and saves the information.
App2 loads the data and uses it for further processing.



I already read ways to share on ios and found somewhere that it could be possible to write my object data into images or contacts.



Right now, I'm facing the approach of the General Pasteboard.
However, after approx. one hour my object can not be found anymore in the pasteboard (altough it should be persistent see )



Code for storing into the pasteboard:



partial void Testbutton_TouchUpInside(UIButton sender)
{
var pasteboard = UIPasteboard.General;

//Create Data
// 4 * 1 MB
IEnumerable<int> idata = Enumerable.Range(0, 1024);
int iarray = idata.ToArray();
byte data = new byte[1+iarray.Length * sizeof(int)];
Buffer.BlockCopy(iarray, 0, data, 1, data.Length-1);
data[0] = counter++;

NSData nsd = NSData.FromArray(data);

// insert to pasteboard
//pasteboard.SetData(nsd, "mydata");

// nach etwa 1h ist es weg
pasteboard.SetItemProviders(new NSItemProvider {new NSItemProvider(nsd, key)},false,NSDate.DistantFuture);


testlabel.Text = "Inserted Data to Pasteboard";
}


code for reading item:



partial void Testbutton2_TouchUpInside(UIButton sender)
{
var pasteboard = UIPasteboard.General;
bool contains = pasteboard.Contains(new { key });
if(contains)
{
testlabel2.Text = $"Contains {key}";

var data = pasteboard.DataForPasteboardType(key);
var dataBytes = new byte[data.Length];
System.Runtime.InteropServices.Marshal.Copy(data.Bytes, dataBytes, 0, Convert.ToInt32(data.Length));

int ints = new int[(dataBytes.Length-1)/4];
Buffer.BlockCopy(dataBytes, 1, ints, 0, dataBytes.Length - 1);
testlabel.Text = "Loaded " + dataBytes.Length + " bytes";
//testlabel2.Text += "Data = {"+dataBytes[0]+","+String.Join(", ", ints) +"}";

StringBuilder sb = new StringBuilder(1024 );
sb.Append("Data = {" + dataBytes[0]);
foreach (var i1 in ints)
{
sb.Append($", {i1.ToString()}");
}
testlabel2.Text = sb.ToString() + "}";
int i = 123;
}
else
{
testlabel2.Text = $"Contains NOT {key}";
}
}


Can someone tell me what why the object is beeing deleted in this case, or what would be a nice way to share objects (typically bytearrays) between two apps from different developers.
Thanks in advance.







c# ios xamarin.ios uipasteboard






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 21 '18 at 8:56









alexdie01alexdie01

161




161








  • 1





    Pasteboard is for the user to control not an app. If the user selects Copy and Paste that's fine but the app should not do it without user interaction

    – Neil
    Nov 21 '18 at 9:43











  • Thanks for your reply, what approach would you suggest to share files properly between different apps (from different developers/teams). CustomURLscheme might work but then App2 asks for data and App1 gets to foreground. After that App1 has to call an URL for App2 to get App2 back into foreground.

    – alexdie01
    Nov 21 '18 at 9:50
















  • 1





    Pasteboard is for the user to control not an app. If the user selects Copy and Paste that's fine but the app should not do it without user interaction

    – Neil
    Nov 21 '18 at 9:43











  • Thanks for your reply, what approach would you suggest to share files properly between different apps (from different developers/teams). CustomURLscheme might work but then App2 asks for data and App1 gets to foreground. After that App1 has to call an URL for App2 to get App2 back into foreground.

    – alexdie01
    Nov 21 '18 at 9:50










1




1





Pasteboard is for the user to control not an app. If the user selects Copy and Paste that's fine but the app should not do it without user interaction

– Neil
Nov 21 '18 at 9:43





Pasteboard is for the user to control not an app. If the user selects Copy and Paste that's fine but the app should not do it without user interaction

– Neil
Nov 21 '18 at 9:43













Thanks for your reply, what approach would you suggest to share files properly between different apps (from different developers/teams). CustomURLscheme might work but then App2 asks for data and App1 gets to foreground. After that App1 has to call an URL for App2 to get App2 back into foreground.

– alexdie01
Nov 21 '18 at 9:50







Thanks for your reply, what approach would you suggest to share files properly between different apps (from different developers/teams). CustomURLscheme might work but then App2 asks for data and App1 gets to foreground. After that App1 has to call an URL for App2 to get App2 back into foreground.

– alexdie01
Nov 21 '18 at 9:50














0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53408367%2fshare-files-on-ios-between-different-apps%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53408367%2fshare-files-on-ios-between-different-apps%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

How to fix TextFormField cause rebuild widget in Flutter