What I'm trying to do currently is basically I have 2 apps and based on if the other one is installed or not, behave in a certain way. I came upon Pasteboard for inter-app communication so I thought I should use those. Well here is the problem, both apps do something like this
UIPasteboard *pasteboard = [UIPasteboard pasteboardWithName:@"com.company.app.key" create:YES];
[pasteboard setPersistent:YES];
NSData *data = [pasteboard dataForPasteboardType:@"com.company.otherapp"];
if(data != nil)
{
// Do stuff
}
NSData *selfKey = [pasteboard dataForPasteboardType:@"com.company.thisapp"];
if(data == nil)
{
[pasteboard setValue:@"string" forPasteboardType:@"com.company.thisapp"];
}
So I installed one app and ran the other, and the first time it worked, data wasn't nil, and if I converted the NSData to NSString using the NSString initializer with NSData, I read "string".
The problem is that all I do is close the second app, run it again and suddenly data is nil. I thought at first that after I access it, the pasteboard just deletes it, so I added the following line in // Do stuff
[pasteboard setValue@"string" forPasteboardType:@"com.company.otherapp"];
Nope data is still nil if I run the app the second time. I need the string to stay in the Pasteboard forever since its all I have to tell me if my other app is installed or not, so does anyone have any ideas why data is returning nil only after 1 run?
I must note that all I am doing is pressing the home button and then running the app again,
so the situation is
-Run app1
-Run app2 (gets the data from Pasteboard)
-press home button
-Run app2 (data now nil)