Friday, August 02, 2013

iOS Tip: Specifying Hardware Requirements

If your application uses special hardware (such as front camera) in order to work, you need to specify that in your info.plist file. Failure to do so will likely anger users who have downloaded (or even paid) for your application only to realize that the app does not work on their devices because they don’t have the correct hardware. Specifying the hardware requirements thus prevents users who do not have the appropriate hardware (as required by your app) from being to purchase your app. But what about specifying hardware that the users should not have? For example, you only want your app to run on the iPod touch and iPad. Hence you need to specify that the device must not have the telephony feature.

To specify the hardware required by your app, you simply need to specify the hardware features in the info.plist file in your project:


However, by default the Property List editor only allows you to set the Required device capabilities key (the raw key name is UIRequiredDeviceCapabilities ) as an array type. This means that you can only set the hardware required by your app, and not the features that you want to exclude. In the above example, your app will require a device running on armv7, has telephony feature (i.e. iPhones), and has a front-facingcamera.

If you want to specify feature(s) that your app do not need, you need to represent the UIRequiredDeviceCapabilities as a dictionary type.

This is how you do it. Right-click on the -info.plist file and select Open As | Source Code. This will show the .plist file as an XML file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>CFBundleDevelopmentRegion</key>
    <string>en</string>
    <key>CFBundleDisplayName</key>
    <string>${PRODUCT_NAME}</string>
    <key>CFBundleExecutable</key>
    <string>${EXECUTABLE_NAME}</string>
    <key>CFBundleIdentifier</key>
    <string>net.learn2develop.${PRODUCT_NAME:rfc1034identifier}
</string>
    <key>CFBundleInfoDictionaryVersion</key>
    <string>6.0</string>
    <key>CFBundleName</key>
    <string>${PRODUCT_NAME}</string>
    <key>CFBundlePackageType</key>
    <string>APPL</string>
    <key>CFBundleShortVersionString</key>
    <string>1.0</string>
    <key>CFBundleSignature</key>
    <string>????</string>
    <key>CFBundleVersion</key>
    <string>1.0</string>
    <key>LSRequiresIPhoneOS</key>
    <true/>
    <key>UIRequiredDeviceCapabilities</key>
    <array>
        <string>armv7</string>
        <string>telephony</string>
        <string>front-facing-camera</string>
    </array>
    <key>UISupportedInterfaceOrientations</key>
    <array>
        <string>UIInterfaceOrientationPortrait</string>
        <string>UIInterfaceOrientationLandscapeLeft</string>
        <string>UIInterfaceOrientationLandscapeRight</string>
    </array>
</dict>
</plist>
As you can see, our three requirements are specified in the element, each represented by a element. To change the UIRequiredDeviceCapabilities to the dictionary type, add in the following statements in bold:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>CFBundleDevelopmentRegion</key>
    <string>en</string>
    <key>CFBundleDisplayName</key>
    <string>${PRODUCT_NAME}</string>
    <key>CFBundleExecutable</key>
    <string>${EXECUTABLE_NAME}</string>
    <key>CFBundleIdentifier</key>
    <string>net.learn2develop.${PRODUCT_NAME:rfc1034identifier}
</string>
    <key>CFBundleInfoDictionaryVersion</key>
    <string>6.0</string>
    <key>CFBundleName</key>
    <string>${PRODUCT_NAME}</string>
    <key>CFBundlePackageType</key>
    <string>APPL</string>
    <key>CFBundleShortVersionString</key>
    <string>1.0</string>
    <key>CFBundleSignature</key>
    <string>????</string>
    <key>CFBundleVersion</key>
    <string>1.0</string>
    <key>LSRequiresIPhoneOS</key>
    <true/>
    <key>UIRequiredDeviceCapabilities</key>
    <dict>
        <key>armv7</key>
        <true/>
        <key>telephony</key>
        <false/>
        <key>front-facing-camera</key>
        <true/>
    </dict>
    <key>UISupportedInterfaceOrientations</key>
    <array>
        <string>UIInterfaceOrientationPortrait</string>
        <string>UIInterfaceOrientationLandscapeLeft</string>
        <string>UIInterfaceOrientationLandscapeRight</string>
    </array>
</dict>
</plist>

In the example above, we specified that the telephony feature as false. That is, our app can only run on an iPod touch,  iPad, or iPad mini.

If you now right-click the info.plist file and select Open As | Property List, you will see the following:


No comments: