1

在我的应用程序中,我有一个日志机制,它为客户提供了通过邮件发送日志的可能性。为此,我在我的应用程序中集成了 Apple MFMailComposeViewController。如果客户使用低操作系统版本 (2.x) 的设备或设备上未显示电子邮件帐户,我推送了一些 UIAlertsView 并为用户提供了一些提示性消息。有人可以看看我下面的代码,如果有什么可能导致苹果拒绝的东西,请回复?

BOOL canSendmail = [MFMailComposeViewController canSendMail];

if (!canSendmail) {


    NSMutableString* osVersion = [NSMutableString stringWithString:[[UIDevice currentDevice] systemVersion]];
    EventsLog* logs = [EventsLog getInstance];

    if ([osVersion characterAtIndex : 0] == '2'  || [osVersion characterAtIndex : 0] == '1' ) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Email", @"") 
                                                        message:NSLocalizedString(@"Failed to send E-mail.For this service you need to upgrade the iPhone OS to 3.0 version or later", @"")
                                                       delegate:self cancelButtonTitle:NSLocalizedString(@"OK", @"") otherButtonTitles: nil];
        [alert show];
        [alert release];



        [logs writeEvent : @"Cannot send e-mail - iPhone OS needs upgrade to at least 3.0 version" classSource:@"LogsSessionDetailViewController@sendEmail" details : (@" device OS version is %@",osVersion)];

        return;

    }
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Email", @"") 
                                                    message:NSLocalizedString(@"Failed to send E-mail.Please set an E-mail account and try again", @"")
                                                   delegate:self cancelButtonTitle:NSLocalizedString(@"OK", @"") otherButtonTitles: nil];
    [alert show];
    [alert release];

    [logs writeEvent : @"Cannot send e-mail "  
          classSource:@"LogsSessionDetailViewController@sendEmail" details : @"-  no e-mail account activated"];

    return;
}



UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Email", @"") 
                message:NSLocalizedString(@"The data you are sending will be used to improve the application. You are free to add any personal comments in this e-mail", @"")
                delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", @"") otherButtonTitles: nil];

[alert addButtonWithTitle:NSLocalizedString(@"Submit", @"")];
[alert show];
[alert release];

非常感谢,

亚历克斯。

4

1 回答 1

2

我不会说应用商店的准入/拒绝,但你的代码必须在 iPhone OS 2.x 上崩溃——你打电话

BOOL canSendmail = [MFMailComposeViewController canSendMail];

without checking if this call is possible (MFMailComposeViewController class is not available on 2.x system). Also manual checking of OS version is not a good practice. Instead you must at first check if MFMailComposeViewController present in current runtime:

if ( !NSClassFromString(@"MFMailComposeViewController") ){
    // Put code that handles OS 2.x version
    return;
}

if (![MFMailComposeViewController canSendMail]){
    // Put code that handles the case when mail account is not set up
    return;
}

//Finally, create and send your log
...

P.S. Do not forget that you must set linkage type for MessageUI framework as 'weak' in target settings - you application will crash on old systems on start if you linkage type will be 'required' (default value).

于 2010-10-22T12:16:34.600 回答