开发者

Check if iPhone can send texts w/ MFMessageComposeViewController

I am building an app that takes advantage of 4.0 features like in-app messaging but I also want my app to work on all 3.x versions. How do I check if开发者_JAVA技巧 the device can use MFMessageComposeViewController?


Apple advises to use the NSClassFromString function to determine if the class is available. Don't forgot to weak link against the message framework as mentioned before.

Example from the MessageComposer sample:

-(IBAction)showSMSPicker:(id)sender {
//  The MFMessageComposeViewController class is only available in iPhone OS 4.0 or later. 
//  So, we must verify the existence of the above class and log an error message for devices
//      running earlier versions of the iPhone OS. Set feedbackMsg if device doesn't support 
//      MFMessageComposeViewController API.
Class messageClass = (NSClassFromString(@"MFMessageComposeViewController"));

if (messageClass != nil) {          
    // Check whether the current device is configured for sending SMS messages
    if ([messageClass canSendText]) {
        [self displaySMSComposerSheet];
    }
    else {  
        feedbackMsg.hidden = NO;
        feedbackMsg.text = @"Device not configured to send SMS.";

    }
}
else {
    feedbackMsg.hidden = NO;
    feedbackMsg.text = @"Device not configured to send SMS.";
}
}

Link: MessageComposer sample

Update: The sample code I posted checks for the availability of the SMS composer, checking for the mail composer is similar.


Try this:

#import <MessageUI/MessageUI.h>
#include <dlfcn.h>

if ( dlsym(RTLD_DEFAULT, "MFMailComposeErrorDomain") != NULL ) {
        // MFMessageComposeViewController framework is available
} else {
        // do alternative for no MFMessageComposeViewController
}

Don't forget to weak link the MFMessageUI framework.


You could check the device's current operating system using the UIDevice class.

http://developer.apple.com/iphone/library/documentation/uikit/reference/UIDevice_Class/Reference/UIDevice.html

The systemName and systemVersion properties may be what you're looking for. You'll also need to weak link the framework!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜