附加到电子邮件的文件 - 我正在尝试打开myapp

时间:2011-09-06 18:26:36

标签: iphone email xcode4 info.plist

我找到了几个帖子并在行之间阅读我在info.plist中添加了3个部分。当我运行我的应用程序时,电子邮件有一个带有“ntdb”后缀的附件,但是电子邮件似乎无法识别该扩展名。我假设我必须在plist中输入错误但是在过去2天尝试了每个组合之后我不知道还有什么要改变。谁能告诉我我做错了什么?电子邮件中的文件名是日期和ntdb,如:“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>

1 个答案:

答案 0 :(得分:0)

永远找到这个工作......终于明白了。下面的plist是你需要的。另外,plist实际上是MyAppName-info.plist我从来不知道自己这个文件是完整命名的。

在下面的文件中更改以适合您的应用:

MyAppName - 更改为应用名称

MyCompanyName - 更改为“公司”

MyfileExtensionSuffix - 这是您文件的后缀,例如zip文件就是ZIP。

如果电子邮件正在运行,请终止该进程,以便获取该名称。当您打开带有后缀扩展名的附件的电子邮件时,它将打开您的应用程序。

<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>

在你的app委托中你需要这样的东西:

  

- (void)CopyArg0:(NSURL *)url {       if(url!= nil&amp;&amp; [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   属性:无];

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

消息:@“文件已添加到您的文档中.blaaa blaaa etc”   delegate:self cancelButtonTitle:@“OK”otherButtonTitles:nil];

    [alertStandard show];
    [alertStandard release];


}
 }
     

- (BOOL)应用程序:(UIApplication *)应用程序handleOpenURL :( NSURL   *)url {

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

    return YES;

}

return NO;
 }
     
      
  • (BOOL)应用程序:(UIApplication *)应用程序   didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  •   
     

{

     

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

     

}