Programmatically control iPhone OS versions to enable functions for both OS 3.x and 4 - MFMessageComposeViewController problem

后端 未结 6 647
轮回少年
轮回少年 2021-02-06 12:33

In order to support iPhone OS 3.x and 4.0 I programmatically control MFMessageComposeViewController functionality like this (use it only if the OS version is 4.0 or above):

6条回答
  •  -上瘾入骨i
    2021-02-06 12:54

    You need to make sure you're doing a few things:

    In your target's build settings:

    • set Base SDK to iPhone Device 4.0
    • set iPhone OS Deployment Target to iPhone OS 3.1.3 (or lower)

    In your target's general settings, under Linked Libraries, change the "Type" next to MessageUI.framework to Weak.

    Don't import or it will crash on launch in 3.x. Just import

    I don't know what os_version_num is, but here's the code I use to test for the availability of MFMessageComposeViewController:

    Class smsClass = (NSClassFromString(@"MFMessageComposeViewController"));
    if (smsClass != nil && [MFMessageComposeViewController canSendText]) {
       MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
       controller.body = text;
       controller.recipients = [NSArray arrayWithObjects: nil];
       controller.messageComposeDelegate = self;
       [self presentModalViewController:controller animated:YES];
       [controller release];                
    }
    

提交回复
热议问题