I have read the answer to this question, Identify new iPhone model on xcode (5, 5c, 5s) and would like to add this as an NSString to my MFMailCompose. I have tried using this method but am not having any luck. Someone please help me.
Sorry I am new to Xcode.
NSString *iOS = [[UIDevice currentDevice] systemVersion];
NSString *model = [[UIDevice currentDevice] model];
NSString *appVersionString = [[NSBundle mainBundle] objectForInfoDictionaryKey:#"CFBundleShortVersionString"];
NSString *name = [[UIDevice currentDevice] name];
NSString *appID=#" ";
NSString *appStoreURL =[NSString stringWithFormat:#"https://itunes.apple.com/us/app/scanmarks/id926114469?ls=1&mt=8", appID];
NSString *body = [NSString stringWithFormat:#"I need help with\n\n\n----------\n Name: %#\nDevice: %# (%#)\n Scanmarks Version: %#\n",name,model,iOS,appVersionString];
It currently shows:
I would like it to show the iPhone Device model like Tweetbot does
I have added the suggested and now have this:
Using the link you you put in your question, if you just want it to say the iPhone platform you would just use this portion of their answer :
size_t size;
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
char *machine = malloc(size);
sysctlbyname("hw.machine", machine, &size, NULL, 0);
NSString *platform = [NSString stringWithCString:machine encoding:NSUTF8StringEncoding];
free(machine);
That will translate to iPhone7,2 etc. just pass the NSString *platform = [NSString stringWithCString:machine encoding:NSUTF8StringEncoding]; string 'platform' into your message body
If you want to convert that to whatever string you want that's when the other portion comes into play. This is the only time you'll use the other part and all of the conversions in their answer:
NSString *convertPlatformToString = [self platformType:platform]);
Example for putting in mail message:
size_t size;
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
char *machine = malloc(size);
sysctlbyname("hw.machine", machine, &size, NULL, 0);
NSString *platform = [NSString stringWithCString:machine encoding:NSUTF8StringEncoding];
free(machine);
NSString *body = [NSString stringWithFormat:#"Platform is %#", platform];
Harvey,
I built an open source tool that does exactly what you want. Feel free to use it or browse through the code to see how I accomplished what you're asking.
https://github.com/michaelpatzer/MPFeedbackMailComposeViewController
Related
Is there a way to programmatically detect iOS version's build number,
For example iOS version 9.0.2(13A452).
I know how to detect iOS version eg: 9.0.2.
Is there any API to detect 13A452?
Thanks in advance.
Figured I'd put the code up incase anyone needs it (works at run time), since it's slightly tricky to process!
MAKE SURE YOU #include <sys/sysctl.h>
//make sure you `#include <sys/sysctl.h>`
NSString *ctlKey = #"kern.osversion";
BOOL buildValueFound;
NSString *buildValue;
size_t size = 0;
if (sysctlbyname([ctlKey UTF8String], NULL, &size, NULL, 0) == -1) {
buildValueFound = NO;
} else {
char *machine = calloc( 1, size );
sysctlbyname([ctlKey UTF8String], machine, &size, NULL, 0);
NSString *ctlValue = [NSString stringWithCString:machine encoding:[NSString defaultCStringEncoding]];
free(machine);
buildValue = ctlValue;
buildValueFound = YES;
}
if (buildValueFound) {
NSLog(#"%#", buildValue);
} else {
NSLog(#"No build value found");
}
I have figured this out. Using KERN_OSVERSION on function sysctl returns iOS build number.
I am a new developer in iOS Developing. I faced a problem on current device. According to requirement i have to design app for all device. So anybody can help me how to get Current device & current platform of iOS?
For current device i am using this code:
NSString *deviceType = [[UIDevice currentDevice] model];
My requirement is i have to adjust UITableView row height according to device.
I think you got my question. If you need any information please tell me.
Thanks in advanced.
Ok try this one.
NSString *deviceType = [[UIDevice currentDevice] model]; // for current device
if ([deviceType isEqualToString:#"iPhone"])
{
NSString *platform = [self platformRawString];
NSLog(#"platform :%#",platform);
// To set the half cut in the last cell.
if ([platform isEqualToString:#"iPhone2,1"])
//cellHeight = 39.5;
else if ([platform isEqualToString:#"iPhone4,1"])
//cellHeight = 42;
else if ([platform isEqualToString:#"iPhone5,3"] || [platform isEqualToString:#"iPhone5,4"])
//cellHeight = 42.5;
else
//cellHeight = 40.0;
}
Method for getting platform
- (NSString *)platformRawString
{
size_t size;
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
char *machine = malloc(size);
sysctlbyname("hw.machine", machine, &size, NULL, 0);
NSString *platform = [NSString stringWithUTF8String:machine];
free(machine);
return platform;
}
I'm a starter in obj-c programming and I need to know how to display device info ( name, device type, ios version )
I you know the answer, please tell me and keep in mind i'm a starter with xcode ;)
I've used these information in an App that I developed so I did the following code. I think this may help you. I just didn't understand what you mean with device type.
To get the device model:
// get model from UIDevice
NSString *modelDevice = [UIDevice currentDevice].model;
To get the iOS Version:
//get the iOS version
NSString *systemVersion = [[UIDevice currentDevice] systemVersion];
To get the device name:
/** Method responsible to get the device name
*
* #return device Name
*/
+ (NSString *)deviceName
{
size_t size;
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
char *machine = malloc(size);
sysctlbyname("hw.machine", machine, &size, NULL, 0);
NSString *platform = [NSString stringWithUTF8String:machine];
free(machine);
return platform;
}
You may try something like this: I use this for in-app support emailing from users.
#import <sys/utsname.h>
- (void)yourMethod
{
struct utsname systemInfo;
uname(&systemInfo);
NSString *appVersion = [NSBundle mainBundle].infoDictionary[#"CFBundleVersion"];
NSString *osVersion = [[UIDevice currentDevice] systemVersion];
NSString *machine = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
}
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])
;
Please refer to UIDevice Class. It has all accessible system information properties. This is a singleton class. You can access this class instance like this : [UIDevice currentDevice]
For example if you want to access device model, you can access like this :
[UIDevice currentDevice]. model
Please refer this link to get information about all properties : https://developer.apple.com/library/ios/documentation/uikit/reference/UIDevice_Class/Reference/UIDevice.html
This question already has answers here:
Objective-c iPhone percent encode a string?
(8 answers)
Closed 8 years ago.
I'm trying to encode url string using Objective-c
// 1. Get string
char res = ((char)(400));
NSString *unencodedString = [NSString stringWithFormat:#"%c",res];
// 2. Encode string
static NSString *escape = #":/?&=;+!##$()',*[]";
NSString *result = (__bridge_transfer NSString *)
CFURLCreateStringByAddingPercentEscapes(
NULL,
(__bridge CFStringRef)unencodedString,
NULL,
(__bridge CFStringRef)escape,
kCFStringEncodingUTF8);
// result = %C2%90
But result is not that I expect. Because I get %C6%90 using other programming languages.
As you see Objective-C result is %C2%90, but I expect %C6%90.
Where is my error? Am I do something wrong?
The problem is NSString *unencodedString = [NSString stringWithFormat:#"%c",res] doesn't do what you think it does. char res cannot hold a value larger than 128 (256 for unsigned char).
char res = ((char)(400));
NSString *unencodedString = [NSString stringWithFormat:#"%c",res];
XCTAssertEqualObjects(unencodedString, #"\xc2\x90", #"");
static NSString *escape = #":/?&=;+!##$()',*[]";
NSString *result = (__bridge_transfer NSString *)
CFURLCreateStringByAddingPercentEscapes(
NULL,
(__bridge CFStringRef)unencodedString,
NULL,
(__bridge CFStringRef)escape,
kCFStringEncodingUTF8);
XCTAssertEqualObjects(result, #"%C2%90", #"");
Here is an example which works.
NSString *unencodedString = #"Ɛ";
static NSString *escape = #":/?&=;+!##$()',*[]";
NSString *result = (__bridge_transfer NSString *)
CFURLCreateStringByAddingPercentEscapes(
NULL,
(__bridge CFStringRef)unencodedString,
NULL,
(__bridge CFStringRef)escape,
kCFStringEncodingUTF8);
XCTAssertEqualObjects(result, #"%C6%90", #"");
UPDATE
If you want a sample like this to work, use unichar and -stringWithCharacters:length:.
unichar res = ((unichar)(400));
NSString *unencodedString = [NSString stringWithCharacters:&res length:1];
XCTAssertEqualObjects(unencodedString, #"Ɛ", #"");
static NSString *escape = #":/?&=;+!##$()',*[]";
NSString *result = (__bridge_transfer NSString *)
CFURLCreateStringByAddingPercentEscapes(
NULL,
(__bridge CFStringRef)unencodedString,
NULL,
(__bridge CFStringRef)escape,
kCFStringEncodingUTF8);
XCTAssertEqualObjects(result, #"%C6%90", #"");
I am trying to encrypt/decrypt one field of SQLite3 database stored in iPhone app.
I am using this category mentioned in this question.
While encrypting, I am using following code:
NSString *key = #"pass123";
NSString *secret = webNote.note;
NSData *plain = [secret dataUsingEncoding:NSUTF8StringEncoding];
NSData *cipher = [plain AES256EncryptWithKey:key];
sqlite3_bind_text(statement, 1, [[cipher description] UTF8String], -1, SQLITE_TRANSIENT);
It does save data into the field in 74657874 20746f20 656e6372 797074 format.
But while decrypting, I get blank field (tried everything I knew). I am using following code for decrypting:
char *noteDet = (char *)sqlite3_column_text(statement, 1);
NSString *key = #"pass123";
NSString *secret = [NSString stringWithUTF8String:noteDet];
NSData *secretData = [secret dataUsingEncoding:NSUTF8StringEncoding];
NSData *clean = [secretData AES256DecryptWithKey:key];
aNote.note = ([[NSString alloc] initWithData:clean encoding:NSUTF8StringEncoding])?[[NSString alloc] initWithData:clean encoding:NSUTF8StringEncoding]:#"";
I think, I am unable to convert types. Please guide!
Thanks!
The description of NSData returns something like "" => if you were to read that again you would get different overall data ( and of a higher length ), also you are right that you are not converting the data types correctly.
Try saving the NSData object directly, by saving the bytes themselves rather than the description of the NSData object.
void *bytes = [dataObject bytes];
size_t length = [dataObject length];