Objective-C Getting the device version [duplicate] - objective-c

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Determine device (iPhone, iPod Touch) with iOS
How to check iOS version?
I am using this function to get the device name
NSString *device=[UIDevice currentDevice].model;
it returns me, for example, "iPhone" .
is there a way to get the device version, for example, "iPhone 4S".

#import <sys/utsname.h>
- (NSString *)deviceModel
{
struct utsname systemInfo;
uname(&systemInfo);
return [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
}

try
[[UIDevice currentDevice] platformString]
That will normally return if it is iPhone 4S...

Related

How to record audio and play it with WatchOS2? [duplicate]

This question already has answers here:
Access Apple Watch's microphone
(6 answers)
Closed 7 years ago.
In watchOS 2, Apple has included a new feature to allow apps to record short audio files but, how can I call this new method in my existing WatchKit project?
- (void)presentAudioRecordingControllerWithOutputURL:(NSURL * nonnull)URL
preset:(WKAudioRecordingPreset)preset
maximumDuration:(NSTimeInterval)maximumDuration
actionTitle:(NSString * nullable)actionTitle
completion:(void (^ nonnull)(BOOL didSave,
NSError * nullable error))completion;
My problem is not how to called that method, is that Xcode compiler says that this function is not found. Do I have to include any additional Framework? Could it be because my WatchKit project was create with a previous version of WatchOS?
Thanks!
1) You need to create a file URL at which to store the recorded output.
NSArray *filePaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask,YES);
NSString *path = [[filePaths firstObject] stringByAppendingPathComponent:#"rec.m4a"];
NSURL *fileUrl = [NSURL fileURLWithPath:path];
You may specify the extensions .wav, .mp4, and .m4a.
2) Call the method as follows:
[self presentAudioRecordingControllerWithOutputURL:fileUrl
preset:WKAudioRecordingPresetWideBandSpeech
maximumDuration:5.0
actionTitle:#"Some Title"
completion:^(BOOL didSave, NSError * __nullable error) {
NSLog(#"didSave:%d, error:%#", didSave, error);
}];
You can choose preset in addition to the above
WKAudioRecordingPresetNarrowBandSpeech
WKAudioRecordingPresetHighQualityAudio
In Swift:
self.presentAudioRecordingControllerWithOutputURL(
self.recFileURL(),
preset: WKAudioRecordingPreset.WideBandSpeech,
maximumDuration: 5.0,
actionTitle: "SomeTitle") { (didSave, error) -> Void in
print("didSave:\(didSave), error:\(error)")
}
You can play the recorded file as follows:
self.presentMediaPlayerControllerWithURL(
fileURL,
options: nil) { (didPlayToEnd, endTime, error) -> Void in
print("didPlayToEnd:\(didPlayToEnd), endTime:\(endTime), error:\(error)")
}
You can check the detail specification here.

how to open phone app in iphone without using "tel://123" url [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Can I open phone app using url scheme in iPhone
Within app, I need to launch the phone app. I do not want to dial a call right away like the code below:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#\"tel://911\"]];
....which would just dial 911. I am wondering if I can just launch the phone app. I tried this code:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#\"tel://\"]];
But it doesnot work
Please help me in solving this issue
You can't do that. However if you replace tel: with telprompt: it will prompt the user to confirm the call.
Edit: Also, #"a string" is the syntax literal for NSString. You shouldn't escape the quotes.
Try this code :-
NSString *prefix = (#"tel://123");
UIApplication *app = [UIApplication sharedApplication];
NSString *dialThis = [NSString stringWithFormat:#"%#", prefix];
NSURL *url = [NSURL URLWithString:dialThis];
[app openURL:url];
NOTE : Telephone number should be valid format only
Hope it helps you

XCode - Check with constant if my program is running in simulator o device [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How can I programmatically determine if my app is running in the iphone simulator?
How I can check in XCode 4 with constant if my program is running in simulator o device?
Something like this:
#ifdef RUNING_ON_DEVICE
#else
#endif
There are a couple of options
Preprocessor macro:
#if TARGET_IPHONE_SIMULATOR
//is sim
#elif TARGET_OS_IPHONE
//is real device
#else
//unknown target
#endif
Or, if you'd rather do it in some arbitrary method:
if ([[[UIDevice currentDevice] model] isEqualToString:#"iPhone Simulator"]) {
//device is simulator
}

nomore UDID - how to store settings for push notification per device? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 5 years ago.
Improve this question
Udid deprecated - how would you store the settings for push notification per device now?
How does everyone else store push settings per device?
Can we use the iphone/ipad MAC Address? or will apple ban the app?
Like this:
#interface UIDevice (UIDeviceAppIdentifier)
#property (readonly) NSString *deviceApplicationIdentifier;
#end
#implementation UIDevice (UIDeviceAppIdentifier)
- (NSString *) deviceApplicationIdentifier
{
static NSString *name = #"a string identifying your application, like its name";
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *value = [defaults objectForKey: name];
if (!value)
{
value = (NSString *) CFUUIDCreateString (NULL, CFUUIDCreate(NULL));
[defaults setObject: value forKey: name];
[defaults synchronize]; // handle error
}
return value;
}
#end
the iOS documentation more or less describes use of CFUUIDCreate() to create an identifier and suggests using UserDefaults to store it.
You could try this project
http://www.secureudid.org/

How can I differentiate the iPad and iPhone programmatically? [duplicate]

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
Best way to programmatically detect iPad/iPhone hardware
How can I differentiate the iPad and iPhone programmatically?
It seems for me that the question is a duplicate, but I'll try to brief all I know about device type and iOS version detection.
There are several methods based on which information you want to receive, whether it just device type (iPhone, iPod or iPad) or iOS version.
Here is code for detecting device type (returns i386 in case of Simulator):
#import <sys/utsname.h>
+ (NSString *)getDeviceType {
struct utsname systemInfo;
return [NSString stringWithCString:systemInfo.machine encoding:NSUTF8Encoding];
}
And here is iOS version detector:
+ (float)getOSVersion {
return [[[UIDevice currentDevice] systemVersion] floatValue];
}
And OS detector for compiler:
#ifdef __IPHONE_4_0
//this part of code will be running on devices with os iOS4+
#else
//this part of code will be running on devices with os _UNDER_ iOS4+
#endif
Also, nobody proibits us to use
#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED > 40000
//this part of code will be running on devices with os iOS4+
#endif