Question

I found several posts and reading between the lines I added 3 sections to my info.plist. When I run my app the email has an attached file with the "ntdb" suffix, but email doesnt seem to recognize the extension. I assuming that I must have entered something wrong in the plist but after trying every combination for the last 2 days I dont know what else to change. Can anyone tell me what I did wrong? The filename in the email is a date and ntdb like: "myfile 09-06-2011.ntdb"

<key>CFBundleDocumentTypes</key>
    <array>
        <dict>
            <key>CFBundleTypeIconFiles</key>
            <array>
                <string>icon57</string>
            </array>
            <key>CFBundleTypeName</key>
            <string>myAppName</string>
            <key>CFBundleTypeRole</key>
            <string>Viewer</string>
                <key>LSHandlerRank</key>
                <string>Owner</string>
                <key>LSItemContentTypes</key>
            <array>
                <string>com.myCompanyName.myAppName.ntdb</string>
            </array>
        </dict>
    </array>



<key>UTExportedTypeDeclarations</key>
<array>
    <dict>
        <key>UTTypeConformsTo</key>
        <array>
            <string>public.plain-text</string>
            <string>public.text</string>
        </array>
        <key>UTTypeDescription</key>
        <string>myAppName Backup</string>
        <key>UTTypeIdentifier</key>
        <string>com.myCompanyName.myAppName.ntdb</string>
        <key>UTTypeTagSpecification</key>
        <dict>
            <key>public.filename-extension</key>
            <string>ntdb</string>
            <key>public.mime-type</key>
            <string>text/txt</string>
        </dict>
    </dict>
</array>


    <key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleTypeRole</key>
            <string>Editor</string>
            <key>CFBundleURLIconFile</key>
            <string>icon57</string>
            <key>CFBundleURLName</key>
            <string>com.myCompanyName.myAppName</string>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>myAppName</string>
            </array>
        </dict>
    </array>
Was it helpful?

Solution

Took forever to find this working... got it finally. The plist below is what you need. Also the plist is actually MyAppName-info.plist I was never sure myself what this file was named in full.

Change these in the file below to fit your app:

MyAppName - Change to the name of your app

MyCompanyName - Change to your "company"

MyfileExtensionSuffix - this is the suffix on your file, like a zip file would be ZIP for example.

If Email is running kill that process so it picks up the name. When you open the email with an attached file with the suffix extension it will open your app.

<key>CFBundleDocumentTypes</key>
<array>
    <dict>
        <key>CFBundleTypeIconFiles</key>
        <array>
            <string>myAppName x 57</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>myAppName</string>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>LSHandlerRank</key>
        <string>Owner</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>com.myCompanyName.myAppName.myFileExtensionSuffix</string>
        </array>
    </dict>
</array>

<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>CFBundleURLIconFile</key>
        <string>57 icon</string>
        <key>CFBundleURLName</key>
        <string>com.myCompanyName.myAppName.myFileExtensionSuffix</string>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>myAppName</string>
        </array>
    </dict>
</array>


<key>UTExportedTypeDeclarations</key>
<array>
    <dict>
        <key>UTTypeConformsTo</key>
        <array>
            <string>public.data</string>
        </array>
        <key>UTTypeDescription</key>
        <string>myAppName Backup</string>
        <key>UTTypeIdentifier</key>
        <string>com.myCompanyName.myAppName.myFileExtensionSuffix</string>
        <key>UTTypeSize320IconFile</key>
        <string>myAppName x 114</string>
        <key>UTTypeSize64IconFile</key>
        <string>myAppName x 57</string>
        <key>UTTypeTagSpecification</key>
        <dict>
            <key>public.filename-extension</key>
            <string>myFileExtensionSuffix</string>
            <key>public.mime-type</key>
            <string>application/myAppName</string>
        </dict>
    </dict>
</array>

In your app delegate you need something like this:

-(void) CopyArg0:(NSURL *)url { if(url != nil && [url isFileURL]) { NSData *d = [NSData dataWithContentsOfURL:url]; documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentsDirectory, NSUserDomainMask, YES);

documentsDir = [[NSString alloc]

initWithFormat:@"%@",[documentPaths objectAtIndex:0] ];

[[NSFileManager defaultManager]createFileAtPath:[documentsDir

stringByAppendingPathComponent:[url lastPathComponent]] contents:d attributes:nil];

    alertStandard = [[UIAlertView alloc] initWithTitle:@""  

message:@"The file has been added to your documents. blaaa blaaa etc" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];

    [alertStandard show];
    [alertStandard release];


}
 }

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {

if(url != nil && [url isFileURL])
{
    [self CopyArg0:url];

    return YES;

}

return NO;
 }
  • (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{

NSURL *url = (NSURL *)[launchOptions valueForKey:UIApplicationLaunchOptionsURLKey]; if (url != nil && [url isFileURL]) { [self CopyArg0:url];
}

}

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top