How to Programmatically Get iOS's Alphanumeric Version String

How to programmatically get iOS's alphanumeric version string

Not sure why others are saying that this is not possible because it is using the sysctl function.

#import <sys/sysctl.h>    

- (NSString *)osVersionBuild {
int mib[2] = {CTL_KERN, KERN_OSVERSION};
u_int namelen = sizeof(mib) / sizeof(mib[0]);
size_t bufferSize = 0;

NSString *osBuildVersion = nil;

// Get the size for the buffer
sysctl(mib, namelen, NULL, &bufferSize, NULL, 0);

u_char buildBuffer[bufferSize];
int result = sysctl(mib, namelen, buildBuffer, &bufferSize, NULL, 0);

if (result >= 0) {
osBuildVersion = [[[NSString alloc] initWithBytes:buildBuffer length:bufferSize encoding:NSUTF8StringEncoding] autorelease];
}

return osBuildVersion;
}

How to get the system version build of iOS device like 14D27 for iOS 10.2.1

This alphanumeric string is the build number, and this answer explains a way to get it. Good luck!

Which iOS app version/build number(s) MUST be incremented upon App Store release?

Apple Technical Note TN2420, Version Numbers and Build Numbers

Summary:

  • The pair (Version, Build number) must be unique.

    • The sequence is valid: (1.0.1, 12) -> (1.0.1, 13) -> (1.0.2, 13) -> (1.0.2, 14) ...
  • Version (CFBundleShortVersionString) must be in ascending sequential order.
  • Build number (CFBundleVersion) must be in ascending sequential order.

Version Number and Build Number Checklist


Here are some things you can check when submitting a new build to the App Store. Making sure you have your Version Number and Build Number set properly will help you by avoiding having your App automatically rejected for having them improperly configured.

  1. For each new version of your App, you need to invent a new Version Number. This number should be a greater value than the last Version Number that you used. Though you may provide many builds for any particular release of your App, you only need to use one new Version Number for each new release of your App.
  2. You cannot re-use Version Numbers.
  3. For every new build you submit, you will need to invent a new Build Number whose value is greater than the last Build Number you used (for that same version).
  4. You can re-use Build Numbers in different release trains, but you cannot re-use Build Numbers within the same release train. For macOS apps, you cannot re-use build numbers in any release train.

Based on the checklist, the following (Version, Build Number) sequence is valid too.

  • Case: reuse Build Number in different release trains. (NOTE: NOT macOS app)

    (1.0.0, 1) -> (1.0.0, 2) -> ... -> (1.0.0, 11)
    -> (1.0.1, 1) -> (1.0.1, 2)

Remove all non-numeric characters from a string in swift

I was hoping there would be something like stringFromCharactersInSet() which would allow me to specify only valid characters to keep.

You can either use trimmingCharacters with the inverted character set to remove characters from the start or the end of the string. In Swift 3 and later:

let result = string.trimmingCharacters(in: CharacterSet(charactersIn: "0123456789.").inverted)

Or, if you want to remove non-numeric characters anywhere in the string (not just the start or end), you can filter the characters, e.g. in Swift 4.2.1:

let result = string.filter("0123456789.".contains)

Or, if you want to remove characters from a CharacterSet from anywhere in the string, use:

let result = String(string.unicodeScalars.filter(CharacterSet.whitespaces.inverted.contains))

Or, if you want to only match valid strings of a certain format (e.g. ####.##), you could use regular expression. For example:

if let range = string.range(of: #"\d+(\.\d*)?"#, options: .regularExpression) {
let result = string[range] // or `String(string[range])` if you need `String`
}

The behavior of these different approaches differ slightly so it just depends on precisely what you're trying to do. Include or exclude the decimal point if you want decimal numbers, or just integers. There are lots of ways to accomplish this.


For older, Swift 2 syntax, see previous revision of this answer.

Getting iPhone unique number

For each iPhone, MAC address is unique ( except for iOS Simulator ). You can obtain the information to identify the device. This question will guide you to get MAC address. However, iOS7 disallows use of MAC address. Therefore, for iOS 6 or before, you can use MAC address; for the coming iOS 7, you can use the following method.

Since iOS 6, Apple suggests to use Advertising Identifier, which can be found in ASIdentifierManager class. Example code:

NSUUID *uuid = [ASIdentifierManager advertisingIdentifier];

How to get the UDID in iOS 6 and iOS 7

UDID is no longer available in iOS 6+ due to security / privacy reasons. Instead, use identifierForVendor or advertisingIdentifier.

identifierForVendor:

An alphanumeric string that uniquely identifies a device to the app’s
vendor. (read-only)

The value of this property is the same for apps that come from the
same vendor running on the same device. A different value is returned
for apps on the same device that come from different vendors, and for
apps on different devices regardless of vendor.

advertisingIdentifier:

An alphanumeric string unique to each device, used only for serving
advertisements. (read-only)

Unlike the identifierForVendor property of UIDevice, the same value is
returned to all vendors. This identifier may change—for example, if
the user erases the device—so you should not cache it.

This post explains it well.

Also, see Apple's documentation for the identifierForVendor and advertisingIdentifier.

Programmatically change UITextField Keyboard type

There is a keyboardType property for a UITextField:

typedef enum {
UIKeyboardTypeDefault, // Default type for the current input method.
UIKeyboardTypeASCIICapable, // Displays a keyboard which can enter ASCII characters, non-ASCII keyboards remain active
UIKeyboardTypeNumbersAndPunctuation, // Numbers and assorted punctuation.
UIKeyboardTypeURL, // A type optimized for URL entry (shows . / .com prominently).
UIKeyboardTypeNumberPad, // A number pad (0-9). Suitable for PIN entry.
UIKeyboardTypePhonePad, // A phone pad (1-9, *, 0, #, with letters under the numbers).
UIKeyboardTypeNamePhonePad, // A type optimized for entering a person's name or phone number.
UIKeyboardTypeEmailAddress, // A type optimized for multiple email address entry (shows space @ . prominently).
UIKeyboardTypeDecimalPad, // A number pad including a decimal point
UIKeyboardTypeTwitter, // Optimized for entering Twitter messages (shows # and @)
UIKeyboardTypeWebSearch, // Optimized for URL and search term entry (shows space and .)

UIKeyboardTypeAlphabet = UIKeyboardTypeASCIICapable, // Deprecated

} UIKeyboardType;

Your code should read

if(user is prompted for numeric input only)
[textField setKeyboardType:UIKeyboardTypeNumberPad];

if(user is prompted for alphanumeric input)
[textField setKeyboardType:UIKeyboardTypeDefault];

How to get unchanged device id from ios7 device programmatically

I have solved this by using advertisingIdentifier.

As I have seen there that advertisingIdentifier is

"An alphanumeric string unique to each device, ..."

For that I have used it as the unique identifier (though it is used for the
serving advertisements).

My code is:

-(NSString*)UniqueAppId
{
NSString *Appname = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"];
NSString *strApplicationUUID = [SSKeychain passwordForService:Appname account:@"manab"];
if (strApplicationUUID == nil)
{
strApplicationUUID = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];
[SSKeychain setPassword:strApplicationUUID forService:Appname account:@"manab"];
}
return strApplicationUUID;
}

and just calling it when needed as

[self UniqueAppId];


Related Topics



Leave a reply



Submit