我可以設置我的iPhone應用程序在用戶打開電子郵件附件時運行嗎?

[英]Can I set my iPhone app to run when a user opens an e-mail attachment?


Is there any way to run my app when the user taps on an e-mail attachment, so I can access the attached file?

當用戶點擊電子郵件附件時,有沒有辦法運行我的應用程序,所以我可以訪問附件?

What I want to do is implement some kind of backup / restore for app data:

我想要做的是為app數據實現某種備份/恢復:

  1. The user sends an e-mail with an attached data file that has a special extension (I will be using the new iPhone 3.0 message composer class)
  2. 用戶發送帶有附加數據文件的電子郵件,該文件具有特殊擴展名(我將使用新的iPhone 3.0消息編寫器類)

  3. If the user loses his data, they will be able to go to their e-mail box and open the last e-mail they sent with the app data file
  4. 如果用戶丟失了他的數據,他們將能夠轉到他們的電子郵箱並打開他們隨應用數據文件發送的最后一封電子郵件

  5. Then they simply tap on the attached file, which causes my app to run and restore from that file
  6. 然后他們只需點擊附件,這會導致我的應用程序從該文件運行和恢復

Is it technically possible to perform the last step?

技術上是否可以執行最后一步?

Thanks

3 个解决方案

#1


Mobile Orchard has a great tutorial, describing how to restore your applications database through Custom URL handlers of a serialized SQL Lite database: Lite To Paid iPhone Application Data Migrations With Custom URL Handlers

Mobile Orchard有一個很棒的教程,描述了如何通過序列化SQL Lite數據庫的自定義URL處理程序恢復應用程序數據庫:Lite使用自定義URL處理程序支付iPhone應用程序數據遷移

(paraphrased instructions from the article)

(文章中的釋義說明)

  1. Setup a custom URL handler in your project's Info.plist Setup a custom URL handler http://www.mobileorchard.com/wp-content/uploads/2009/01/result.png
  2. 在項目的Info.plist中設置自定義URL處理程序設置自定義URL處理程序http://www.mobileorchard.com/wp-content/uploads/2009/01/result.png

  3. In your email message convert your database or application data to NSData base64, and include it in a URL For example:

    在您的電子郵件中,將您的數據庫或應用程序數據轉換為NSData base64,並將其包含在URL中例如:

    [NSString stringWithFormat: @"myapplication://localhost/importDatabase?%@",encodedStringData]

    [NSString stringWithFormat:@“myapplication:// localhost / importDatabase?%@”,encodedStringData]

  4. Add a handleOpenURL method to your AppDelegate implementation

    將handleOpenURL方法添加到AppDelegate實現中

Example AppDelegate Implementation:

示例AppDelegate實現:

#import "GTMBase64.h"

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
    if([@"/importDatabase" isEqual:[url path]]) {
        NSString *query = [url query];
        NSString *importUrlData = [GTMBase64 webSafeDecodeString:query];

        // NOTE: In practice you will want to prompt the user to confirm before you overwrite their files!
        [importUrlData writeToFile:@"/path/to/FullApplication/Documents/file" atomically:YES];
        return YES;
    }
    return NO;
}

Mobile Orchard on File size limitations:

移動果園的文件大小限制:

We have transferred files of up to 100k this way, and the size of a URL string is theoretically only limited by available memory. That said, this approach is most suitable for applications with small to medium size data transfer requirements. Best of all though, it can be easily used for SQLite databases, XML files, text files, or even extended to handled compressed archives.

我們以這種方式傳輸了高達100k的文件,理論上URL字符串的大小僅受可用內存的限制。也就是說,這種方法最適合具有中小尺寸數據傳輸要求的應用。最重要的是,它可以很容易地用於SQLite數據庫,XML文件,文本文件,甚至可以擴展到處理壓縮檔案。

#2


I don't think you can have your application run for a particular file type, but you can register it as listening for a particular URL scheme, see for instance:

我認為您的應用程序不能針對特定的文件類型運行,但您可以將其注冊為偵聽特定的URL方案,例如,請參閱:

http://iosdevelopertips.com/cocoa/launching-your-own-application-via-a-custom-url-scheme.html

so if your application data isn't too huge, you might be able to use a custom base64-encoded URL like

因此,如果您的應用程序數據不是太大,您可能可以使用自定義base64編碼的URL

mycustomappbackup://[lots of data here]

mycustomappbackup:// [這里有很多數據]

#3


My App (Listomni) uses the URL approach to backup the database and mail it, and also for migration from the lighter apps into the full version. We additionally compress the serialized SQLite database, which saves a lot of room. However, it's less than optimal for backup purposes with intensive amounts of data because if users forward the mail via GMail or Outlook, then both clients have a tendency to truncate the URL to 2048 bytes.

我的應用程序(Listomni)使用URL方法備份數據庫並將其郵寄,以及從較輕的應用程序遷移到完整版本。我們另外壓縮了序列化的SQLite數據庫,這節省了大量的空間。但是,對於具有大量數據的備份目的而言,它不是最佳的,因為如果用戶通過GMail或Outlook轉發郵件,則兩個客戶端都傾向於將URL截斷為2048字節。

I was also hoping since we can now send attachments with iPhone OS 3.0, that we could also register filetypes, to later retrieve them, but sadly doesn't look like this is supported yet. shakes fist at Apple

我也希望,因為我們現在可以發送iPhone OS 3.0的附件,我們也可以注冊文件類型,以便以后檢索它們,但遺憾的是看起來還不支持。在蘋果公司握拳


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2009/07/24/7256c1505bfa0fd529437245c9fc68e4.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com