AIR IOS应用注册文件类型,由第三方APP通过Open with启动

在IOS里,这个叫Document Interaction ,通过在info.plist文件里进行设置实现文件关联
在AIR里,-app.xml文件内iphone/InfoAdditions下的key/value内容都会被添加到info.plist. 内容参考IOS的即可
<key>CFBundleDocumentTypes</key> // 文档类型
  <array>
    <dict>  // 每个Dict对应一个类型
      <key>CFBundleTypeName</key>
      <string>txt</string>
      <key>LSHandlerRank</key>
      <string>Owner</string> // 设为Owner时,文档会COPY到documents/inbox文件夹下
      <key>LSItemContentTypes</key>
      <array>
        <string>com.youapp.txt</string>
        <string>public.plain-text</string>
      </array>  
    </dict>
  </array>
<key>UTExportedTypeDeclarations</key> // 导出类型定义
  <array>
    <dict>  每个Dict对应一个类型
      <key>UTTypeConformsTo</key>
      <array>
        <string>public.plain-text</string>
        <string>public.text</string>
      </array>
      <key>UTTypeDescription</key>
      <string>Text File</string>
      <key>UTTypeIdentifier</key>
      <string>com.youapp.txt</string>
      <key>UTTypeTagSpecification</key>
      <dict>
        <key>public.filename-extension</key>
        <string>txt</string>
        <key>public.mime-type</key>
        <string>text/plain</string>
      </dict>
    </dict>
  </array>
AIR应用通过InvokeEvent事件可接收到文件进行后续处理.

private function preinitializeHandler():void {
  NativeApplication.nativeApplication.addEventListener(InvokeEvent.INVOKE, invokeHandler);
}
private function invokeHandler(event:InvokeEvent):void {
  var items:Array = event.arguments;
  if( items.length > 0 ) {
    var file:File = new File( event.arguments[0] );
    // your code …
  }    
}
来源:Apps开发网

Using the iPad retina display with Adobe Air

Using the iPad retina display with Adobe Air

19th March 2012

Last Friday, the new iPad was launched by Apple, with its new retina display. I did a few tests to try to use the high-resolution retina screen at its maximum resolution from Adobe Air. Here are the results.

The simple option doesn’t work

The first thing to note is that Apple deliberately limited the new retina resolution to Apps built with the iOS 5.1 SDK. This is to avoid incompatibility issues with Apps that were released before the new iPad was available. So apps built with earlier versions of the iOS SDK use pixel doubling and have an effective resolution of 1024×768 pixels, like the iPad 2.By default, Adobe Air compiles with iOS 4.0. I don’t know what’s special about iOS 4.0 that Adobe can distribute this version with Air but not later versions, but that’s the way it is. So, if you compile your Air app the normal way, you will not get retina resolution on the new iPad. Everything will still work fine, but it will use pixel doubling to get the same results as on the iPad 2.

Compiling with iOS 5.1

If you have a Mac, there is a solution. Adobe Air since Air 3.1 includes a build setting to specify the version of the iOS SDK to use. The setting is the platformsdk and you can read more about it on this Adobe blog. If you read through the comments in that post you’ll see that this is only supported when compiling on OSX, at the moment, but Adobe hope to bring it to Windows sometime in the future.So, if you have a Mac, download and install XCode. In the new XCode, the SDK is inside the application package – the filepath is /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk/. Now use the playformsdk setting to build against iOS 5.1.

via Using the iPad retina display with Adobe Air.

The test

To test this I built a little app, with just a few lines of code –

package com.sticksports.test
{
  import flash.display.Sprite;
  import flash.display.StageAlign;
  import flash.display.StageScaleMode;
  import flash.events.Event;
  import flash.system.Capabilities;
  import flash.text.TextField;

  public class RetinaTest extends Sprite
  {
    public function RetinaTest()
    {
      stage.scaleMode = StageScaleMode.NO_SCALE;
      stage.align = StageAlign.TOP_LEFT;
      addEventListener( Event.ENTER_FRAME, getStats );
    }

    private function getStats( event : Event ) : void
    {
      removeEventListener( Event.ENTER_FRAME, getStats );

      var textField : TextField = new TextField();
      textField.width = stage.stageWidth - 40;
      textField.height = stage.stageHeight - 40;
      textField.x = 20;
      textField.y = 20;
      textField.border = true;
      textField.multiline = true;
      addChild( textField );

      textField.appendText( "Capabilities.screenResolutionX : " + Capabilities.screenResolutionX + "\n" );
      textField.appendText( "Capabilities.screenResolutionY : " + Capabilities.screenResolutionY + "\n" );
      textField.appendText( "Capabilities.screenDPI : " + Capabilities.screenDPI + "\n" );
      textField.appendText( "stage.stageWidth : " + stage.stageWidth + "\n" );
      textField.appendText( "stage.stageHeight : " + stage.stageHeight + "\n" );
      textField.appendText( "stage.fullScreenWidth : " + stage.fullScreenWidth + "\n" );
      textField.appendText( "stage.fullScreenHeight : " + stage.fullScreenHeight + "\n" );    }
  }
}

I didn’t use Flash Builder for my tests because I’m an FDT user, so the apps were built from Ant scripts. First I built the swf in the standard way.

&lt;exec executable="${sdk.home}/bin/amxmlc" failonerror="true" dir="../package"&gt;
  &lt;arg line='-source-path ../src'/&gt;
  &lt;arg line='-default-size=960,640'/&gt;
  &lt;arg line='-default-background-color 0xFFFFFF'/&gt;
  &lt;arg line='-default-frame-rate 60'/&gt;
  &lt;arg line='-debug=false'/&gt;
  &lt;arg line='-optimize=true'/&gt;
  &lt;arg line='-swf-version=13'/&gt;
  &lt;arg line='-output RetinaTest.swf'/&gt;
  &lt;arg line='../src/com/sticksports/test/RetinaTest.as'/&gt;
&lt;/exec&gt;

I gave the swf a default size to match the iPhone, just to see what Air gave me as the stage size as a result.

The application descriptor file requests the high resolution display, as for the iPhone retina screen.

&lt;?xml version="1.0" encoding="utf-8" standalone="no"?&gt;
&lt;application xmlns="http://ns.adobe.com/air/application/3.0"&gt;

  &lt;id&gt;com.sticksports.RetinaTest&lt;/id&gt;
  &lt;filename&gt;RetinaTest&lt;/filename&gt;
  &lt;name&gt;Retina Test&lt;/name&gt;
  &lt;versionNumber&gt;0.0.1&lt;/versionNumber&gt;
  &lt;versionLabel&gt;v0.0.1&lt;/versionLabel&gt;
  &lt;copyright&gt;Stick Sports Ltd.&lt;/copyright&gt;

  &lt;initialWindow&gt;
    &lt;content&gt;RetinaTest.swf&lt;/content&gt;
    &lt;aspectRatio&gt;portrait&lt;/aspectRatio&gt;
    &lt;autoOrients&gt;true&lt;/autoOrients&gt;
    &lt;fullScreen&gt;true&lt;/fullScreen&gt;
    &lt;renderMode&gt;cpu&lt;/renderMode&gt;
    &lt;softKeyboardBehavior&gt;none&lt;/softKeyboardBehavior&gt;
    &lt;/initialWindow&gt;

  &lt;icon&gt;
    &lt;image29x29&gt;icons/icon_29.png&lt;/image29x29&gt;
    &lt;image57x57&gt;icons/icon_57.png&lt;/image57x57&gt; 
    &lt;image72x72&gt;icons/icon_72.png&lt;/image72x72&gt; 
    &lt;image114x114&gt;icons/icon_114.png&lt;/image114x114&gt; 
  &lt;/icon&gt;

  &lt;iPhone&gt;
    &lt;InfoAdditions&gt;
      &lt;![CDATA[
        &lt;key&gt;UIDeviceFamily&lt;/key&gt;
        &lt;array&gt;
          &lt;string&gt;1&lt;/string&gt;
          &lt;string&gt;2&lt;/string&gt;
        &lt;/array&gt;
        &lt;key&gt;UIStatusBarStyle&lt;/key&gt;
        &lt;string&gt;UIStatusBarStyleBlackOpaque&lt;/string&gt;
      ]]&gt;
    &lt;/InfoAdditions&gt;
    &lt;requestedDisplayResolution&gt;high&lt;/requestedDisplayResolution&gt;
  &lt;/iPhone&gt;

&lt;/application&gt;

I built the ipa twice, using the Air 3.2 release candidate from Adobe Labs. I built it once using the default version of the iPhone SDK (version 4.0) that is bundled with Air.

&lt;exec executable="${sdk.home}/bin/adt" failonerror="true" dir="../package"&gt;
  &lt;arg value="-package"/&gt;
  &lt;arg value="-target"/&gt;
  &lt;arg value="ipa-ad-hoc"/&gt;
  &lt;arg value="-provisioning-profile"/&gt;
  &lt;arg value="${ios.provisioning.profile}"/&gt;
  &lt;arg value="-storetype"/&gt;
  &lt;arg value="pkcs12"/&gt;
  &lt;arg value="-keystore"/&gt;
  &lt;arg value="${ios.keystore.file}"/&gt;
  &lt;arg value="-storepass"/&gt;
  &lt;arg value="${ios.keystore.password}"/&gt;
  &lt;arg value="../publish/default/RetinaTest.ipa"/&gt;
  &lt;arg value="../build/RetinaTest-app.xml"/&gt;
  &lt;arg value="RetinaTest.swf"/&gt;
  &lt;arg value="Default.png"/&gt;
  &lt;arg value="icons"/&gt;
&lt;/exec&gt;

And once with the iOS 5.1 SDK

&lt;exec executable="${sdk.home}/bin/adt" failonerror="true" dir="../package"&gt;
  &lt;arg value="-package"/&gt;
  &lt;arg value="-target"/&gt;
  &lt;arg value="ipa-ad-hoc"/&gt;
  &lt;arg value="-provisioning-profile"/&gt;
  &lt;arg value="${ios.provisioning.profile}"/&gt;
  &lt;arg value="-storetype"/&gt;
  &lt;arg value="pkcs12"/&gt;
  &lt;arg value="-keystore"/&gt;
  &lt;arg value="${ios.keystore.file}"/&gt;
  &lt;arg value="-storepass"/&gt;
  &lt;arg value="${ios.keystore.password}"/&gt;
  &lt;arg value="../publish/5.1/RetinaTest.ipa"/&gt;
  &lt;arg value="../build/RetinaTest-app.xml"/&gt;
  &lt;arg value="RetinaTest.swf"/&gt;
  &lt;arg value="Default.png"/&gt;
  &lt;arg value="icons"/&gt;
  &lt;arg line="-platformsdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk/"/&gt;
&lt;/exec&gt;

The equivalent command-line script is

adt -package -target ipa-ad-hoc -provisioning-profile YOUR_PROVISIONING_PROFILE -storetype pkcs12 -keystore YOUR_KEYSTORE_FILE -storepass YOUR_KEYSTORE_PASSWORD RetinaTest.ipa RetinaTest-app.xml RetinaTest.swf Default.png icons -platformsdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk/

The results

With the default SDK the results are

Capabilities.screenResolutionX : 768
Capabilities.screenResolutionY : 1024
Capabilities.screenDPI : 132
stage.stageWidth : 960
stage.stageHeight : 640
stage.fullScreenWidth : 768
stage.fullScreenHeight : 1024

I was surprised the stageWidth and stageHeight don’t match the screenResolutionX and screenResolutionY, which is why I use the latter in my projects. As Florian mentioned in the comments, you can also use fullScreenWidth and fullScreenHeight, which I added after reading his comment. Aside from that, there’s no surprises here. The results are the same as on the iPad2.

With iOS 5.1 SDK, the results are

Capabilities.screenResolutionX : 1536
Capabilities.screenResolutionY : 2048
Capabilities.screenDPI : 132
stage.stageWidth : 1536
stage.stageHeight : 2048
stage.fullScreenWidth : 1536
stage.fullScreenHeight : 2048

This version uses the full resolution of the retina screen. The text is half the size on screen because the pixel resolution is doubled and the screenResolutionX and screenResolutionY and fullScreenWidth and fullScreenHeight are the correct size for the retina display. This time, surprisingly, the stageWidth and stageHeight did match the screen resolution – all the more reason not to trust them. Also, the screenDPI is incorrect, showing the same value as the iPad 2.

But, most importantly, the project has access to the full retina screen resolution. Hurrah!

Building with Air 3.1

As I said above, I initially used the public beta of Air 3.2 for this test. I reran the test using Air 3.1 and the results were the same, except building with Air 3.1 and iOS 5.1 gave the stageWidth as 1920px and stageHeight as 1280px. All other results were the same as for Air 3.2.

 

Gesture Recognizers

UIKit includes a UIGestureRecognizer class that defines the basic behavior for all gesture recognizers. You can define your own custom gesture recognizer subclasses or use one of the UIKit-supplied subclasses to handle any of the following standard gestures:

  • Tapping (any number of taps)
  • Pinching in and out (for zooming)
  • Panning or dragging
  • Swiping (in any direction)
  • Rotating (fingers moving in opposite directions)
  • Long presses

iOS获取图片的信息

相册中的图片需要使用 Assets Library Framework 配合获取图片信息

// Get the assets library
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];

// Enumerate just the photos and videos group by using ALAssetsGroupSavedPhotos.
[library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos
usingBlock:^(ALAssetsGroup *group, BOOL *stop)
{

// Within the group enumeration block, filter to enumerate just photos.
[group setAssetsFilter:[ALAssetsFilter allPhotos]];

// For this example, we’re only interested in the first item.
[group enumerateAssetsAtIndexes:[NSIndexSet indexSetWithIndex:0]
options:0
usingBlock:^(ALAsset *alAsset, NSUInteger index, BOOL *innerStop)
{

// The end of the enumeration is signaled by asset == nil.
if (alAsset) {
ALAssetRepresentation *representation = [alAsset defaultRepresentation];
NSDictionary *imageMetadata = [representation metadata];
// Do something interesting with the metadata.
}
}];
}
failureBlock: ^(NSError *error)
{
// Typically you should handle an error more gracefully than this.
NSLog(@”No groups”);
}];

[library release];

[转]Run your Flash apps in Xcode iOS Simulator with AIR 3.3

AIR 3.3 adds a new feature to preview and debug your apps directly in iOS Simulator that is part of Xcode on Mac. This rapidly speeds up testing and preview of an app or a game especially when you use native extensions.

[Download AIR 3.3 SDK]
[ADT command documentation]

Simulator support is not yet part of the Flash Builder, but you can already use it via command-line:

Compile for iOS Simulator
There two new options available with adt for iOS Simulator compilation:
1) ipa-test-interpreter-simulator (for testing)
2) ipa-debug-interpreter-simulator (for debugging)

PATH_TO_AIR33SDK/bin/adt -package
-target ipa-test-interpreter-simulator
-provisioning-profile DEMO.mobileprovision
-keystore CERTIFICATE.p12
-storetype PKCS12
-storepass PASSWORD FINALAPP.ipa DESCRIPTOR.xml APP.swf

The command in Terminal.app on Mac:

Install to iOS Simulator
In order to install app to iOS Simulator use -installApp switch. See usage below:

PATH_TO_AIR33SDK/bin/adt -installApp
-platform ios
-platformsdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk
-device ios-simulator
-package FINALIPA.ipa

Launch app in iOS Simulator
To launch app, there is the -launchApp switch used together with the -appid.

PATH_TO_AIR33SDK/bin/adt -launchApp
-platform ios
-platformsdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk
-device ios-simulator
-appid com.krcha.IDofMyApplication

Uninstall app from iOS Simulator
Use -uninstallApp switch. See below:

PATH_TO_AIR33SDK/bin/adt -uninstallApp
-platform ios
-platformsdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk
-device ios-simulator
-package com.krcha.IDofMyApplication

In the real world, it’s good to put the commands above in separate .sh or .bat files. You can also combine them into a single command to run your app even faster. Usually this way:
run.sh
1) compile.sh
2) uninstall.sh
3) install.sh
4) launch.sh

Important note: in order to make native extensions run properly in iOS Simulator, you have to compile them with iPhone-x86 settings, not iPhone-ARM.
In extension.xml change platform name

&lt;platform name=”iPhone-x86″&gt;

Waste Invaders running in the iOS Simulator.

http://www.flashrealtime.com/ios-simulator-air-flash-xcode/

[转]AIR开发ios游戏总结

最近开发了一个农场类游戏,游戏不算大,功能还算齐全。
我向大家说一样开发中遇到的问题:
1,尽量使用位图,如果是纯色块的话,可以用矢量。
2,资源和素材最好用外部加载的方式,特别是皮肤,这样可以动态的更新皮肤
3,遮罩的效率不高,如果非要用的话,最好把里面的图片先加载好。因为在移动设备里,外部资源加载消耗很大,可以在游戏刚开始把大部分加载好。
4,字体上是关键,最好选择设备有的字体,不要嵌入字体。嵌入的字体会出现问题,而且效率很低很低,特别是在ipad3和低清设备上面。如果你不知道有什么字体,可以在”越 狱”的ios机子上,用91软件,可以把上面的字体全部弄下来。
5,游戏中只使用一次的东西,可以用到的时候再加载,用完后就卸掉。像每日奖励这种,就可以这样做。
6,我们用AIR3.2打包后,会出现设备crash。用AIR3.1和3.3没有问题。但是3.1有个小问题,ipad3 loading那儿图片会斜一下,不过问题不大。
7,如果图形上面要求不是很高,可以只做两套UI,一套是iphone大小,一套ipad2大小,如果是低清设备,就把ihpone大小基础上缩小一倍,如果是ipad3就在ipad2大小基础上加大一倍。
8,最好把游戏进程和UI动画用不同的两个EnterFrame来控制。这样在一些大的UI弹出窗时,可以先暂停游戏进程。
9,做ios游戏,尽量用itouch来测试游戏。如果能在itouch上面跑得不错,自然在iphone,ipad上面问题就不大。
10,不需要鼠标操作的,要把mouseEnabled设置成false ,如果它的子对象也不需要鼠标事件,要把mouseChildren设置为false。
11,如果对手指触摸精确度要求不是很高,可以只用MouseEvent事件,一是方便测试,二是消耗CPU少。
13,如果要存储本地文件和数据,要把数据存储到File.applicationStorageDirectory下面,一是为了设备兼容性,二是这样软件更新的话,数据还在。
14,如果开发游戏的话,一定要用原生的AS项目,纯AS项目要比flex项目效率高很多。
15,尽可能早的真机测试,能更快地发现问题。
16,现在flash builder4.6及以上版本都能方便地打包ipa,完全可以不用adt命令行。

iOS Data Storage Guidelines 和 “do not back up”文件属性

iOS 5有了iCloud后,Apple更新了数据存储指导方针,以适应于iCloud存储,同时增加了“不要备份”文件属性,可以指定文件不备份和上传到iCloud

摘录如下,供大家参考:

iOS 数据存储指导方针


iCloud包括了备份,会通过Wi-Fi每天自动备份用户iOS设备。app的home目录下的所有东西都会被备份,除了应用Bundle本身、缓存目录和temp目录。已购买的音乐、应用、书籍、Camera Roll、设备设置、主屏幕、App组织、消息、铃声也都会被备份。由于备份通过无线进行,并且为每个用户存储在iCloud中,应用需最小化自己存储的数据数量。大文件会延长备份时间,并且消耗用户的可用iCloud空间。


为了确保备份尽可能快速高效,应用存储数据需要遵循以下指导方针:


1. 只有那些用户生成的文档或其它数据,或者应用不能重新创建的数据,才应该存储在<Application_Home>/Documents目录下,并且会被自动备份到iCloud。


2. 可以重新下载或生成的数据,应该存储在<Application_Home>/Library/Caches目录。例如数据库缓存文件、可下载文件(杂志、报纸、地图应用使用的数据)等都属于这一类。


3. 临时使用的数据应该存放在<Application_Home>/tmp目录。尽管这些文件不会被iCloud备份,应用在使用完之后需要记得删除这些文件,这样才不会继续占用用户设备的空间。


4. 使用”不要备份”属性来指定那些需要保留在设备中的文件(即使是低存储空间情况下)。那些能够重新生成,但在低存储空间时仍需保留,对应用正常运行有影响,或者用户希望文件在离线时可用的文件,需要使用这个属性。无论哪个目录下的文件(包括Documents目录),都可以使用这个属性。这些文件不会被删除,也不会包含在用户的iCloud或iTunes备份中。由于这些文件一直占用着用户设备的存储空间,应用有责任定期监控和删除这些文件。








iOS 5.0.1开始支持”do not back up”文件属性,允许开发者明确地指定哪些文件应该被备份,哪些是本地缓存可以自动删除,哪些文件不需要备份但不能删除。此外,对目录设置这个属性,会阻止备份该目录和目录中的所有内容。


注意”do not back up”属性只能用于iOS 5.0.1以后版本。之前版本的应用需要存储数据到<Application_Home>/Library/Caches目录才能避免被备份。由于老的系统忽略这个属性,你需要确保应用在所有iOS版本中,都遵循上面的iOS Data Storage Guidelines。


数据处理分类
com.apple.MobileBackup文件属性就是iOS 5.0.1引入的”do not back up”特性,用于指定文件或目录不需要备份(不管在文件系统的什么位置)。通过使用这个新的文件属性,并且将文件存放在指定的目录下,文件可以分为以下四种数据类型:s.


关键数据
这些是用户创建的数据,或其它不能重新生成的数据。应该存放在<Application_Home>/Documents目录下,并且不应该标记为”do not backup”属性。关键数据在低存储空间时也会保留,而且会被iCloud或iTunes备份。


缓存数据
可以重新下载或生成的数据,而且没有这些数据也不会妨碍用户离线使用应用的功能。缓存数据应该保存在<Application_Home>/Library/Caches目录下。缓存数据在设备低存储空间时可能会被删除,iTunes或iCloud不会对其进行备份。


临时数据
应用需要写到本地存储,内部使用的临时数据,但不需要长期保留使用。临时数据应该保存在<Application_Home>/tmp目录。系统可能会清空该目录下的数据,iTunes或iCloud也不会对其进行备份。应用在不需要使用这些数据时,应该尽快地删除临时数据,以避免浪费用户的存储空间。


离线数据
可以下载,或重新创建,但用户希望在离线时也能访问这些数据。离线数据应该存放在<Application_Home>/Documents目录或<Application_Home>/Library/Private Documents目录,并标记为”do not backup”属性。这两个位置的数据在低存储空间时都会保留,而”do not backup”属性会阻止iTunes或iCloud备份。应用不再需要离线数据文件时,应该尽快删除,以避免浪费用户的存储空间。ce.




设置Do Not Backup扩展属性
注意:”do not backup”扩展属性可以添加到任何文件或目录,在旧版本的系统中也能够设置。但旧系统仍然会备份这些文件,一旦设备更新到iOS 5.0.1,这些文件会被重新正确地配置。


使用下面方法来设置”do not back up”扩展属性。当你创建不需要备份的文件或目录时,向文件写入数据,然后调用下面方法,并传递一个文件URL。


设置扩展属性
#include <sys/xattr.h>
– (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL
{
    c*****t char* filePath = [[URL path] fileSystemRepresentation];

    c*****t char* attrName = “com.apple.MobileBackup”;
    u_int8_t attrValue = 1;

    int result = setxattr(filePath, attrName, &attrValue, sizeof(attrValue), 0, 0);
    return result == 0;
}