Identify device's IOS version dynamically [duplicate] - iphone

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Check iPhone iOS Version
I'm building an app that has an SMS composer (which isn't available in 3.0).
How can I find the underlying device's OS version dynamically and make the SMS option available, and if not disable the function.

Here is the piece of code which will give you all the info about device
NSLog(#"uniqueIdentifier: %#", [[UIDevice currentDevice] uniqueIdentifier]);
NSLog(#"name: %#", [[UIDevice currentDevice] name]);
NSLog(#"systemName: %#", [[UIDevice currentDevice] systemName]);
NSLog(#"systemVersion: %#", [[UIDevice currentDevice] systemVersion]);
NSLog(#"model: %#", [[UIDevice currentDevice] model]);
NSLog(#"localizedModel: %#", [[UIDevice currentDevice] localizedModel]);
you can get here the version number.
But i will suggest you to go with checking that the phone supports mail composer,sms or not
like
Class messageClass = (NSClassFromString(#"MFMessageComposeViewController"));
if (messageClass != nil) {
// Check whether the current device is configured for sending SMS messages
if ([messageClass canSendText])
{
MFMessageComposeViewController *msgpicker = [[MFMessageComposeViewController alloc] init];
msgpicker.messageComposeDelegate = self;
msgpicker.recipients = [NSArray arrayWithObject:[self.productInfoArray valueForKey:#"Phone"]]; // your recipient number or self for testing
msgpicker.body = #"test from OS4";
NSLog(#"chat view array %#",[self.productInfoArray valueForKey:#"Phone"]);
[self presentModalViewController:msgpicker animated:YES];
[msgpicker release];
NSLog(#"SMS fired");
}
else { NSLog(#"chat view array %#",[self.productInfoArray valueForKey:#"Phone"]);
NSLog(#"Device not configured to send SMS.") ;
UIAlertView *alert= [[UIAlertView alloc]initWithTitle:#"Status" message:#"Device not configured to send SMS." delegate:self cancelButtonTitle:#"OK" otherButtonTitles:#"cancel",nil];
[alert show];
[alert release];
}
}
This will help to resolve your problem.
Happy Coding
Cheers................

The UIDevice class has a systemVersion property you can use to get the OS version. This'll return the version value such as 3.1 or 4.2. Guess you can use this to determine access to your SMS functionality.
#property (nonatomic, readonly, retain) NSString *systemVersion
Check out the reference for more info >
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIDevice_Class/Reference/UIDevice.html

I think you could use NSClassFromString(#"MFMessageComposeViewController") to see if the class is available.
(Caveat: You couldn't check for UIGestureRecognizer this way because Apple used private class with the same name. Same could be true for MFMessageComposeViewController.)

Related

Is it possible to tweet a photo with the Twitter APIs in iOS5? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
iOS 5 Attach photo to Twitter with Twitter API
Some Twitter clients have a photo tweet feature. Does the iOS 5 Twitter API also include a way to tweet a photo?
Read this : TWTweetComposeViewController Class Reference
and the - addImage property
Yes of course
if ([[[UIDevice currentDevice] systemVersion] floatValue] > 5.0) {
// Create the view controller
TWTweetComposeViewController *twitter = [[TWTweetComposeViewController alloc] init];
// Optional: set an image, url and initial text
[twitter addImage:[UIImage imageName:#"YourImage.png"]];
[twitter setInitialText:#"I created this photo Download http://www.twetter.com"];
// Show the controller
[self presentModalViewController:twitter animated:YES];
// Called when the tweet dialog has been closed
twitter.completionHandler = ^(TWTweetComposeViewControllerResult result)
{
NSString *title = #"Tweet Status";
NSString *msg;
if (result == TWTweetComposeViewControllerResultCancelled)
msg = #"Tweet compostion was canceled.";
else if (result == TWTweetComposeViewControllerResultDone)
msg = #"Tweet composition completed.";
// Show alert to see how things went...
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:title message:msg delegate:self cancelButtonTitle:#"Okay" otherButtonTitles:nil];
[alertView show];
// Dismiss the controller
[self dismissModalViewControllerAnimated:YES];
};
}
There is need to use TWTweetComposeViewController Class Reference
Refer ios-5-attach-photo-to-twitter-with-twitter-api link for code.

How do you make a call from your app? [duplicate]

I need to call programmatically in my app in a button click.
for that i found code like this.
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"tel:1-800-555-1212"]];
Is it work in iphone sdk 3.0 and iphone 2.0 also
Can any pls help
Thank u in advance.
Keep the phone number in a separate string.
NSString *phoneNumber = #"1-800-555-1212"; // dynamically assigned
NSString *phoneURLString = [NSString stringWithFormat:#"tel:%#", phoneNumber];
NSURL *phoneURL = [NSURL URLWithString:phoneURLString];
[[UIApplication sharedApplication] openURL:phoneURL];
NSLog(#"Phone calling...");
UIDevice *device = [UIDevice currentDevice];
NSString *cellNameStr = [NSString stringWithFormat:#"%#",self.tableCellNames[indexPath.row]];
if ([[device model] isEqualToString:#"iPhone"] ) {
NSString *phoneNumber = [#"tel://" stringByAppendingString:cellNameStr];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];
} else {
UIAlertView *warning =[[UIAlertView alloc] initWithTitle:#"Note" message:#"Your device doesn't support this feature." delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[warning show];
}
// VKJ
The following code snippet checks if SIM card is present or not as well if the device is capable of making the call such as non-sim ios devices
#import <CoreTelephony/CTTelephonyNetworkInfo.h>
#import <CoreTelephony/CTCarrier.h>
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:#"tel://"]]) {
// Check if iOS Device supports phone calls
CTTelephonyNetworkInfo *netInfo = [[CTTelephonyNetworkInfo alloc] init];
CTCarrier *carrier = [netInfo subscriberCellularProvider];
NSString *mnc = [carrier mobileNetworkCode];
// User will get an alert error when they will try to make a phone call in airplane mode.
if (([mnc length] == 0)) {
// Device cannot place a call at this time. SIM might be removed.
} else {
// iOS Device is capable for making calls
}
} else {
// iOS Device is not capable for making calls
}
if ( ! [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:#"sms:"]]) {
// iOS Device is not capable to send SMS messages.
}
Don't forget to add the CoreTelephony framework
Credit

How to make a call programmatically?

I need to call programmatically in my app in a button click.
for that i found code like this.
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"tel:1-800-555-1212"]];
Is it work in iphone sdk 3.0 and iphone 2.0 also
Can any pls help
Thank u in advance.
Keep the phone number in a separate string.
NSString *phoneNumber = #"1-800-555-1212"; // dynamically assigned
NSString *phoneURLString = [NSString stringWithFormat:#"tel:%#", phoneNumber];
NSURL *phoneURL = [NSURL URLWithString:phoneURLString];
[[UIApplication sharedApplication] openURL:phoneURL];
NSLog(#"Phone calling...");
UIDevice *device = [UIDevice currentDevice];
NSString *cellNameStr = [NSString stringWithFormat:#"%#",self.tableCellNames[indexPath.row]];
if ([[device model] isEqualToString:#"iPhone"] ) {
NSString *phoneNumber = [#"tel://" stringByAppendingString:cellNameStr];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];
} else {
UIAlertView *warning =[[UIAlertView alloc] initWithTitle:#"Note" message:#"Your device doesn't support this feature." delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[warning show];
}
// VKJ
The following code snippet checks if SIM card is present or not as well if the device is capable of making the call such as non-sim ios devices
#import <CoreTelephony/CTTelephonyNetworkInfo.h>
#import <CoreTelephony/CTCarrier.h>
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:#"tel://"]]) {
// Check if iOS Device supports phone calls
CTTelephonyNetworkInfo *netInfo = [[CTTelephonyNetworkInfo alloc] init];
CTCarrier *carrier = [netInfo subscriberCellularProvider];
NSString *mnc = [carrier mobileNetworkCode];
// User will get an alert error when they will try to make a phone call in airplane mode.
if (([mnc length] == 0)) {
// Device cannot place a call at this time. SIM might be removed.
} else {
// iOS Device is capable for making calls
}
} else {
// iOS Device is not capable for making calls
}
if ( ! [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:#"sms:"]]) {
// iOS Device is not capable to send SMS messages.
}
Don't forget to add the CoreTelephony framework
Credit

Is it safe to check for UI_USER_INTERFACE_IDIOM() to determine if it's an iPhone or iPad?

I've found this code, here:
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
str = [NSString stringWithString:#"Running as an iPad application"];
} else {
str = [NSString stringWithString:
#"Running as an iPhone/iPod touch application"];
}
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Platform"
message:str
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
How safe is this check? Does Apple actually recommend doing this? Or can it happen that it won't detect an iPad as iPad, or iPhone as iPhone?
It should be safe enough, it's well-documented by Apple.
That is just shorthand for the following code:
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
// etc
It could conceivably fail if you tried to run this on anything less than iOS 3.2 (as it was only introduced then), but this might not be an issue for you.

is it possible to open Settings App using openURL?

I know an app can launch other apps by using this code: [[UIApplication sharedApplication] openURL:appUrl];. And I know the scheme of URL to open safari and mail, but I did some searches and found nothing about the scheme of settings.app.
You can open settings apps programmatically try this(works only from iOS8 onwards).
If you are using Swift:
UIApplication.sharedApplication().openURL(NSURL(string: UIApplicationOpenSettingsURLString))
If you are using Objective-C
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
For other lower versions(less than iOS8) its not possible to programatically open settings app.
You can use this in iOS versions 5.0 - 5.0.1. It was then deprecated in iOS 5.1.
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"prefs://"]];
Opening settings apps programmatically is possible only from iOS 8. So, use the following code from http://code-ios.blogspot.in/2014/10/opening-settings-app-from-another-app.html
if([CLLocationManager locationServicesEnabled]&&
[CLLocationManager authorizationStatus] != kCLAuthorizationStatusDenied)
{
//...Location service is enabled
}
else
{
if([[[UIDevice currentDevice] systemVersion] floatValue]<8.0)
{
UIAlertView* curr1=[[UIAlertView alloc] initWithTitle:#"This app does not have access to Location service" message:#"You can enable access in Settings->Privacy->Location->Location Services" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[curr1 show];
}
else
{
UIAlertView* curr2=[[UIAlertView alloc] initWithTitle:#"This app does not have access to Location service" message:#"You can enable access in Settings->Privacy->Location->Location Services" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:#"Settings", nil];
curr2.tag=121;
[curr2 show];
}
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSLog(#"buttonIndex:%d",buttonIndex);
if (alertView.tag == 121 && buttonIndex == 1)
{
//code for opening settings app in iOS 8
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
}
}
Swift 4 version:
if let url = URL(string: UIApplicationOpenSettingsURLString) {
UIApplication.shared.openURL(url)
}