Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

BlueSpud

macrumors newbie
Original poster
Feb 12, 2014
6
0
Hello,
I've been at this for easily 10 hours and I haven't been able to figure out what should be a tribal task. I have created a custom file for users to be able to email to each other. I believe I've defined it correctly, but I could be wrong. When I airdrop the file, it works fine. It will open in my app and dropbox. Thats fine. However, when I email the file something strange happens. It wants to open with Facebook, twitter, etc. Then all the way at the end of that list is my app. Obviously this is a problem because these can't do anything with my file. I've scoured the depths of the internet including apple's documentation an I still haven't solved the problem. I'd love it if anyone could help me out on this because it seems that I can't find a solution ANYWHERE. Here is the code that is related to the files and the sharing.

The relevant stuff in the info.plist:
Code:
<key>CFBundleDocumentTypes</key>
	<array>
		<dict>
			<key>CFBundleTypeIconFiles</key>
			<array>
				<string>HydrantBig@2x</string>
			</array>
			<key>CFBundleTypeName</key>
			<string>Fire PrePlan</string>
			<key>CFBundleTypeRole</key>
			<string>Viewer</string>
			<key>LSHandlerRank</key>
			<string>Owner</string>
			<key>LSItemContentTypes</key>
			<array>
				<string>com.bluespud.prp</string>
			</array>
		</dict>
	</array>
	<key>UTExportedTypeDeclarations</key>
	<array>
		<dict>
			<key>UTTypeConformsTo</key>
			<array>
				<string>public.data</string>
			</array>
			<key>UTTypeDescription</key>
			<string>Fire PrePlan</string>
			<key>UTTypeIdentifier</key>
			<string>com.bluespud.prp</string>
			<key>UTTypeTagSpecification</key>
			<dict>
				<key>public.filename-extension</key>
				<string>prp</string>
			</dict>
		</dict>
	</array>

The file I'm sending is actually just a png with a few modified metadata pieces. I think this is the best way to do it because I don't have to create a overly complicated file and to much data other than the image needs to be shared. When I do open the file in my app it does load correctly.

Code:
//here is the crap for the activities
    CGImageSourceRef source = CGImageSourceCreateWithData((__bridge CFDataRef)UIImageJPEGRepresentation(image, 1.0), NULL);



    NSMutableDictionary* metadata = [(__bridge NSMutableDictionary *) CGImageSourceCopyPropertiesAtIndex(source, 0, NULL) mutableCopy];
    NSMutableDictionary* customMetadata = [[metadata objectForKey:(NSString *)kCGImagePropertyExifDictionary]mutableCopy];

    CFStringRef UTI = CGImageSourceGetType(source);

    NSMutableData* data = [NSMutableData data];

    CGImageDestinationRef destination = CGImageDestinationCreateWithData((__bridge CFMutableDataRef)data, UTI, 1, NULL);

    NSString* superAwesomeMegaString = [[DataController.places objectAtIndex:DataController.active] stringByAppendingString:[@"<end>" stringByAppendingString:[[DataController.Notes objectAtIndex:DataController.active] stringByAppendingString:[@"<end>" stringByAppendingString:[[DataController.numbers objectAtIndex:DataController.active]stringByAppendingString:[@"<end>" stringByAppendingString:[DataController.locks objectAtIndex:DataController.active]]]]]]];
    //a few additional things. The above its already too long
    superAwesomeMegaString = [superAwesomeMegaString stringByAppendingString:@"<end>"];

        for (int j = 0; j < DataController.iconList->at(DataController.active).size(); j++)
        {
            //make the string

            superAwesomeMegaString = [superAwesomeMegaString stringByAppendingString:[[NSString alloc] initWithFormat:@"%i,%i,%i",  DataController.iconList->at(DataController.active)[j].x,  DataController.iconList->at(DataController.active)[j].y,  DataController.iconList->at(DataController.active)[j].identifier]];
            if (j < DataController.iconList->at(DataController.active).size() - 1)
                superAwesomeMegaString = [superAwesomeMegaString stringByAppendingString:@"?"];
        }



    [customMetadata setObject:superAwesomeMegaString forKey:(NSString*)kCGImagePropertyExifUserComment];
    //[customMetadata setObject:[DataController.Notes objectAtIndex:DataController.active] forKey:@"Place_Notes"];
    //[customMetadata setObject:[DataController.numbers objectAtIndex:DataController.active] forKey:@"Place_Number"];

    [metadata setObject:customMetadata forKey:(NSString*)kCGImagePropertyExifDictionary];

    CGImageDestinationAddImageFromSource(destination, source, 0, (__bridge CFDictionaryRef)metadata);
    CGImageDestinationFinalize(destination);

    NSString* filePath = [[NSString alloc] initWithFormat:@"%@/%@.prp",[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0],[DataController.places objectAtIndex:DataController.active]];
    [data writeToFile:filePath atomically:YES];

    NSURL* fileURL = [NSURL fileURLWithPath:filePath];
    /*
    NSString* fileUTI = @"";
    [fileURL getResourceValue:&fileUTI forKey:NSURLTypeIdentifierKey error:nil];
    NSLog(@"%@",fileUTI);
    UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef)[fileUTI pathExtension], NULL);
     */
    activities = [[UIActivityViewController alloc] initWithActivityItems:@[fileURL] applicationActivities:nil];
    activities.excludedActivityTypes = @[UIActivityTypeMessage,UIActivityTypePrint];

    /*
     activities.completionHandler = ^(NSString *activityType, BOOL completed)
     {
     [self dismissViewControllerAnimated:YES completion:nil];
     };
     */

For some reason when I check the UTI of the file after the email its not the com.bluespud.prp its dns. something. I don't know if thats relevant at all.

EDIT: Thats not relevant, the same UTI appears when I use airdrop to send the file.

Thank you for any help or input you give.
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.