Detecting Asian characters in a string

With the simple use of a regular expression to find out if a string contains Chinese, Japanese or Korean (aka CJK) characters.


#import <Foundation/Foundation.h>
@interface NSString (CJK)
/**
Detect if the string contains Chinese, Japanese or Korean characters
@return YES if the string contains CJK characters, NO otherwise
*/
– (BOOL)containsAsianCharacters;
@end

view raw

NSString+CJK.h

hosted with ❤ by GitHub


#import "NSString+CJK.h"
@implementation NSString (CJK)
– (BOOL)containsAsianCharacters
{
if (![self length])
return NO;
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"[\u2E80-\u9FFF]" options:NSRegularExpressionCaseInsensitive error:nil];
return ([regex matchesInString:self options:0 range:NSMakeRange(0, [self length])]);
}
@end

view raw

NSString+CJK.m

hosted with ❤ by GitHub

Having fun with iTMSTransporter

I haven’t found much about this strange iTMSTransporter API enabling developers to script communication with iTunes Connect, so I dug and it was worth it.

Objective

I have 25 In-App Purchase products that are hosted by Apple, and these products need to be updated 2 to 4 times a year. Wow, that represents a lot of time, let’s write a script.

The solution : iTMSTransporter

The iTunes Connect
 Transporter is provided by Apple, an installer and the documentation are available through iTunes Connect under the “Resources & Help” section (you need to have a valid iTunes Connect account to access). Guess what? As an Xcode user, it’s already installed since the IDE itself is using the API to communicate with iTunes Connect when you uploading binaries (for instance).

It also can be used to:

  • upload app binaries
  • upload screenshots
  • update app metadata
  • manage app pricing
  • manage In-App Purchase products
  • etc.

Well yes, that’s basically the same possibilities than Application Loader, but scriptable.

How to use it?

Once it installed, let’s say that you have added it to you path, you can use the iTMSTransporter command and try to understand something to the help message.

There are basically 3 modes that can be easily translated into three steps, plus the one where you actually edit the information you want to send to iTunes Connect.

Step 1 : lookup for metadata

In my case, I had to find metadata related to a given In-App Purchase product identifier, so the first step is to download the .itmsp package from iTunes Connect with the following command:

iTMSTransporter -m lookupMetadata -u "$ITC_USERNAME" -p "$ITC_PASSWORD" -vendor_id "$ITC_PRODUCT_PARENT_ID"

Doing such will download a package (aka a directory that OS X will not open directly) with an XML file representing ALL THE DATA about your application. If you just need to update products one by one, you can easily add filters:

iTMSTransporter -m lookupMetadata -u "$ITC_USERNAME" -p "$ITC_PASSWORD" -vendor_id "$ITC_PRODUCT_PARENT_ID" -subitemids "$ITC_PRODUCT_ID" -subitemtype InAppPurchase

Step 2 : update metadata

This is the most challenging part since you need to update the metadata.xml file by adding or editing some fields.

As I was writing a shell script, I used xmlstarlet to work with my xml file. XPath

Note 1: if you want to upload some files (screenshots, .ipa files or .pkg files), you just need to add them to the .itmsp package and update the related fields in the metadata.xml file (such as the size of the file, or the md5 hash).

Note 2: except some required field, all the non-modified fields are ignored, you can safely remove some of them.

Step 3 : verify

iTMSTransporter -m verify -u "$ITC_USERNAME" -p "$ITC_PASSWORD" -f "$ITMSP_PATH"

If this command pass, you can go to the step 4, otherwise, you should carefully read the hints “provided” by Apple in the error log.

Step 4 : upload

iTMSTransporter -m upload -u "$ITC_USERNAME" -p "$ITC_PASSWORD" -f "$ITMSP_PATH"

Note: when the upload is completed, the sent package may take some processing time to appear on iTunes Connect, especially when sending In-App Purchase packages.

Voila !

The documentation found on iTunes Connect if “helpful”, but here is the best source of information I found: http://bou.io/UploadingScreenshotsWithITMSTransporter.html, this is about uploading screenshots but the process can be easily adapted.