文件附加到电子邮件 - 我正在尝试打开myapp [英] File attached to Email - I am trying to open myapp

查看:163
本文介绍了文件附加到电子邮件 - 我正在尝试打开myapp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现几条帖子和阅读之间我添加了3个部分到我的info.plist。当我运行我的应用程序时,电子邮件附带一个带有ntdb后缀的文件,但电子邮件似乎不能识别该扩展名。我假设我必须在plist中输入错误,但是在最后两天尝试了每个组合之后,我不知道还有什么改变。谁能告诉我我做错了什么?电子邮件中的文件名是一个日期和ntdb,如:myfile 09-06-2011.ntdb

 < key> CFBundleDocumentTypes< /密钥GT; 
< 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>所有者< / 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备份< / 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>编辑器< / 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>


解决方案

永远找到这个工作...得到它最后。下面的plist是你需要的。此外,plist实际上是MyAppName-info.plist我从来不知道这个文件是否被完整命名。



将以下文件更改为适合您的应用程序: / p>

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>编辑器< / string>
< key> LSHandlerRank< / key>
< string>所有者< / string>
< key> LSItemContentTypes< / key>
< array>
< string> com.myCompanyName.myAppName.myFileExtensionSuffix< / string>
< / array>
< / dict>
< / array>

< key> CFBundleURLTypes< / key>
< array>
< dict>
< key> CFBundleTypeRole< / key>
< string>编辑器< / string>
< key> CFBundleURLIconFile< / key>
< string> 57图标< / 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备份< / 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>

在您的应用程序委托中,您需要这样:


- (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]]; / p>

  [[NSFileManager defaultManager] createFileAtPath:[documentsDir 

stringByAppendingPathComponent:[url lastPathComponent]]内容:d
属性:nil];

  alertStandard = [[UIAlertView alloc] initWithTitle:@

message:@文件已添加到您的文档中。blaaa blaaa etc
delegate:self cancelButtonTitle:@OKotherButtonTitles:nil];

  [alertStandard show]; 
[alertStandard release];


}
}

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

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

返回YES;

}

return NO;
}




  • (BOOL)应用程序:(UIApplication *)应用程序
    didFinishLaunchingWithOptions :( NSDictionary *)launchOptions



{



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

}



}



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>

解决方案

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];
}

}

这篇关于文件附加到电子邮件 - 我正在尝试打开myapp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆