iOS Named pasteboard not found on actual device

345 Views Asked by At

I've got a problem with my inter-app communication on iPad which (up to recently) has been working. I'm using standard pasteboard code as found in http://enharmonichq.com/sharing-data-locally-between-ios-apps/ which is an excellent tutorial and works well.

My problem is that now my 'viewer' app is not receiving the pasteboard when it opens.

The code:

+(void)handleSendPasteboardDataURL:(NSURL *)sendPasteboardDataURL
                 completionHandler:(ENHAppDataSharingHandler)completionHandler;
{
    NSString *query = [sendPasteboardDataURL query];
    NSString *pasteboardName = [sendPasteboardDataURL fragment];
    NSAssert2(([query isEqualToString:kReadPasteboardDataQuery] && pasteboardName),
              @"Malformed or incorrect url sent to %@. URL: %@",
              NSStringFromSelector(_cmd), sendPasteboardDataURL);

    AppDataPackage *dataPackage = nil;
    NSError *error = nil;

    NSString *pasteboardType = kAppDataPackageUTI;
    UIPasteboard *pasteboard = [UIPasteboard pasteboardWithName:pasteboardName create:NO];

    if (pasteboard)
    {
        NSData *data = [pasteboard dataForPasteboardType:pasteboardType];
        if (data)
        {
            dataPackage = [AppDataPackage unarchivePackageData:data];
        }
        else
        {
            NSDictionary *errorInfoDictionary = @{NSLocalizedDescriptionKey: [NSString stringWithFormat:
                                                                              @"%@ %@", NSLocalizedString(@"No data found on pasteboard with name:", nil),
                                                                              pasteboardName]};
            error = [NSError errorWithDomain:AppDataSharingErrorDomain
                                        code:ENHAppDataSharingErrorTypeNoDataFound
                                    userInfo:errorInfoDictionary];
        }
        [pasteboard setData:nil forPasteboardType:pasteboardType];
        [pasteboard setPersistent:NO];
    }
    else
    {
        NSDictionary *errorInfoDictionary = @{NSLocalizedDescriptionKey:
                                                  [NSString stringWithFormat:@"%@ %@",
                                                   NSLocalizedString(@"No pasteboard found for name:", nil), pasteboardName]};
        error = [NSError errorWithDomain:AppDataSharingErrorDomain
                                    code:ENHAppDataSharingErrorTypeNoPasteboardForName
                                userInfo:errorInfoDictionary];
    }
    completionHandler(dataPackage, error);
}

This has worked well previously on the device and still works well on the simulator. But now when tested on the device, the call...

[UIPasteboard pasteboardWithName:pasteboardName create:NO];

...fails and the pasteboard is nil. (pasteboard names are valid)

As I said this works OK on the simulator but not on the device.

So my question is if anyone else has had experience with the same problem? Any suggestions as to what it could be?

My source app is working as other pasteboard 'test' apps can receive the data and work on the device. It's just my main receiving app is failing to get the pasteboard in question.

I'm a bit at my whit's end with this one.

This is running iOS7.1.2 and developing on xcode 5.1.1

Thanks

0

There are 0 best solutions below