Is it possible to embed or load SWFs when making iphone apps (Is it allowed by Apple) - iphone

I am a little confused on whether to embed swfs or load them when making apps for the iphone. Does anyone know what are the advantages of each (which is preferable to use)? I know that embedding swfs should be a little faster than loading them but is that all?
Also and this is kind of important, I read that Apple will reject any app with external swfs?? Is that indeed correct? If so, will embedding or loading said swfs solve this problem?
Thanks in advance
EDIT: after some searching around, turns that Apple does have problems with loading external swfs, u can still do it, but your swfs need not have any actionscript attached, here is a link http://whizzkid74.blogspot.com/2010/12/air-for-iphone-loading-external-swf.html It doesnt say anything about embedding swfs however, so my question is this: can u embed swfs when writing apps on the iphone??
EDIT To clarify, when i say external SWFs. I mean SWFs that are found on your system locally but you need to add them to your program since they contain MovieClips or Sprites etc... that u need. I didn't mean SWFs that you need to download from a website or an online source. (hope that clarifies things)
EDIT Changed the question's title...Problem solved, thanks for all the help guys and happy new year =D

Update, Oct 2012:
In Adobe AIR 3.5, adl is introducing a feature called "multiple SWF support" that allows the use of Loaders to load SWFs delivered in the .ipa (local files, not from servers) to have code in them. The adl compiler AOT compiles SWFs that are included in the .ipa, allowing them to be loaded and work under iOS.
AIR 3.5 is currently in beta at the time of this writing, available on the adobe labs site:
AIR 3.5 on Adobe labs website
AIR 3.5 release notes
Note that this feature requires -swf-version=18 or greater of the root SWF (not necessarily the assets being loaded) and AIR namespace ending in 3.5 in the application xml file.
Older answer:
I wanted to update this answer because I've learned a lot about this issue since I first looked into it.
The root of the issue is that, when making iOS apps with AIR, Apple TOS disallows runtime interpretation of code - and this includes SWF bytecode. So loading SWFs with code in them (even simple animation commands like stop(), gotoAndPlay(), etc) is disallowed and will not work via a Loader (prior to AIR 3.5).
Note that it's perfectly fine to load SWFs for their vector graphics content. The graphics will display, but the code will not execute.
However, there are a few workarounds for this. Both workarounds avoid a Loader by compiling assets with code in them into the main SWF, because once they're part of the main SWF, the AIR compiler (adt) will cross-compile the code into objective-c, and everything will work fine on iOS devices.
Using SWC libraries
This is the best option for iOS development. If you compile your graphical assets (.fla file) into SWCs (or export SWCs from symbols in your library), then compile your main swf against these SWCs, this goes through the compiler and actionscript code will execute on iOS devices.
Using SWFMerge for [embed]ed SWFs
Embedding assets into SWFs is very easy, and looks like this:
[Embed(source="GameLevel.swf")]
private var GameLevel:Class;
public function main():void
{
var my_level:* = new GameLevel();
addChild(my_level);
}
In this scenario, if gameLevel.swf has code in it, it typically wouldn't work in iOS, because new gameLevel() would create a Loader and interpret SWF bytecode. But, if you first run the above SWF through my tool called SWFMerge, it will take your embedded SWF and merge it into your root SWF. Then ADT will compile your main swf (including embedded code) into objective-C, it will work on iOS, and note: new gameLevel() now results directly in an instance of your asset - NOT a Loader.
The SWFMerge tool is here:
http://www.onetacoshort.com/temp/SWFMerge_alpha.swf
Let me know in the comments if this workaround works for you or if you have trouble.
Using Loaders
Prior to AIR 3.5, if you use a Loader to load a SWF file (whether this swf is included in your IPA or served from a webserver), the target SWF graphics will load just fine, but no code inside the SWF will execute, again because this is disallowed by Apple's TOS.
As of AIR 3.5, packaging SWF files in the .ipa as assets, using a Loader will work even if they contain code as this code is now AOT-compiled by adt. This requires -swf-version=18 or greater of the root SWF (not necessarily the assets) and AIR namespace ending in 3.5 in the application xml file.
However, it is technically possible to interpret SWF bytecode, it's simply an App Store legal restriction not to. If you only want to test on an iOS device and won't be distributing your app via the App Store, you can compile your SWF using adt's -target ipa-test-interpreter option, and Loading SWFs with code in them will work.

I'm not familiar with the rules around Apple and iPhone apps, but generally when I make apps/games, I embed everything. The advantages:
Your game/app is in one swf, making it easy to share
Your game/app loads quicker as all the assets are there at load-time
You're not dependant on internet access to get your assets (if you're loading them from a site) - good for an app
Your game/app will "just work" - no security issues, no problems with urls changing/asset site going down (if they're external)
If you use a swc instead of an swf (an swc can also be loaded btw), then you can also benefit from strict-typing
The disadvantages:
If you need to update one of your assets, you need to republish the game/app

The answer is yes, you can embed SWFs, but that is not the only way. You can also use normal Loader methods, with everything relative to the main SWF:
var myLoader:Loader = new Loader();
// iOS apps act as if the main SWF is in a folder
// and the other SWFs are in the same (or sub) folders.
var url:URLRequest = new URLRequest("loadedSWF.swf");
myLoader.load(url);
addChild(myLoader);
myLoader.x = 50;
myLoader.y = 30;
With one caveat: during compile time (in the "Air for iOS Settings", in the "Included files" list), you have to list the SWFs that you want to be loaded, and they will get compiled into the IPA.
So, no you cannot call to external SWFs, but you certainly can access other SWFs using the embed tag, or using (what might be called) IPA embedding.
Edit:
Since the question and title have changed a bit since I first answered this, here is a more generic summary. Apple does not allow loading local SWFs in the same way that you would be able to if using Flash Player on a website. There is no way to load an SWF (or anything else) using "relative" or "local" references in an i-device unless that content is compiled into the app. This does not apply to some types of "remote" SWF loading, and also does not apply to Actionscript "Native" coding, but that is not what the (original) question was about.

Related

From SWF to AIR to iOS application

I have existing Flash application, which compiles to SWF and runs on web. I'm looking at converting that application to work on mobile devices such as iPhone/iPad.
I see that there is now a way to publish Adobe Air applications on mobile devices. My thought is why not convert SWF to AIR application and then use that AIR application to publish on mobile devices. Does it make sense? Is this even possible or doable?
What are people doing to convert their existing Flash SWF applications to work on mobile devices?
This question was just answered here, but to recap any Flash content can be packaged to iOS or other mobile device with AIR.
AIR can be overlaid to Flash Professional or Flash Builder, or your SWF can be packaged using the ADT command line packager:
Download AIR 3.0 SDK.
Assure JRE, or use the one from Flash Builder.
Execute adt to package your SWF to an IPA:
adt -package -target [ipa-test | ipa-debug | ipa-app-store | ipa-ad-hoc]
-keystore iosPrivateKey.p12 -storetype pkcs12 -storepass qwerty12
-provisioning-profile ios.mobileprovision
HelloWorld.ipa
HelloWorld-app.xml
HelloWorld.swf icons Default.png
It's important to note that all executable code must reside in a single SWF to run on the iOS platform. SWFLoading or any dynamically loaded SWF that executes code is not supported. So, link all your Flash to a single SWF.
There are other considerations, such as optimizing performance and handling multiple screen resolutions and aspect ratios.
References:
http://www.adobe.com/devnet/air/articles/packaging-air-apps-ios.html
http://www.adobe.com/devnet/air/articles/packaging-air-apps-android.html
http://www.adobe.com/devnet/air/articles/packaging-air-apps-blackberry.html
There are a few ways to achieve this:
You can download Adobe AIR SDK, and follow their help or this tutorial. This method would be a bit tedious if you are not comfortable with command line, but it is perhaps the most powerful option because you get to tweak and control a lot of options.
If you have the FLA file, the latest version of Flash CS6 should provide you the means to create IOS IPA file more effortlessly. If you are a Windows user, you would need to get the p12 file as well as mobile provision file. Adobe has documentations on how to do that without a Mac. Eventually when your IPA is ripe for AppStore, you would need a Mac.
Keep in mind that the user experience of an SWF would not right away translate well for iOS. For example, the size of buttons, the affordance of interactive user controls, and most importantly, mouseover events could sometimes adversely impact the experience of a mobile app.
But those problems have nothing to do with SWF, as I have seen similar issues with other HTML-based web apps too.
Good luck, I would say writing Flash and it runs everywhere including iPhone/iPad is truly an amazing thing that most people don't know.
I have been doing this exact thing for a year or so.
You do have to set up your certificates using the keychain on the Mac, and you have to upload the app from a Mac. However, I do not have a Mac . . . instead, I rent time on a remote Mac using (macincloud or others), and use DropBox to send the files back and forth.
Depending on how the SWF was created, you do not necessarily need to buy Adobe products. I use FlashDevelop, which sets up the latest Air and Flex SDKs automatically. As long as you have a developer's license, you can create the Air application from that, and you can also create the IPA file for loading into iTunes (or Google Play, or others).
Make sure you have read #JasonSturges response as well. Good tips and links.

Create Mobile Apps with Flash for iPhone and Android with Embedded browser

EDIT:
See my answer
I saw some interesting frameworks to build applications for mobile platforms like Android and iPhone with HTML and Javascript so you can use your current web-development skills without learning a new platform language. That's very interesting because you can write just ONE application for many platforms. Very easy to maintain.
But, you cannot sell it in the App stores, so I’m wondering if it is possible to use an embedded webbrowser in the application that loads an external/included html file.
I have seen that it is possible to create Android and iPhone apps with flash, that's is easy, so i want to create a simple 'host' application that only loads content and I can use it over and over again to distribute a new app.
So the question is, is it possible to create a simple app with flash that embeds a webbrowser to load a html file?
When it is possible, next question is, it possible to communicate with the embedded webbrowser? Also a question is, will Apple allow such application in it app store?
I hope my question is understandable.
In a very strict sense, yes, you can make an app that is just a simple WebView wrapper pointing to your web-hosted app.
This is usually frowned upon though in the android market community, and i'm fairly positive such an app won't make it through Apple's closed-doors decision committee.
On the iPhone, if your app only consist of a UIWebView it is very likely that you app is going to be rejected. What you could do is ask your users to bookmark your webapp adding an icon to the home screen. Think Basecamp for iPhone.
After all this time i got the answer.
Phonegap uses a WebView to display the HTML content. It is a compiled native App with embedded WebView.
Apple accepts phonegap generated applications but it still not sure if it made it to the AppStore, it depends on what you doing with it. I think simple apps will made it. See also: http://www.phonegap.com/faq
EDIT/UPDATE:
I tried allot of tools/solutions to create crossplatform apps but all of these seem to do the same thing: It's a executable for the specific platform with an embedded browser. None of them compiles HTML to native code.
Flash (Builder) is something different, it requires AIR (can be compiled into the executable). When you using a WebView (only) with Flash, it is overkill because in fact you do not need AIR to display the HTML in a WebView. I think it is better to use phonegap to 'compile' the executable.

AS3 Packager for iPhone: Can the app download content?

I am in the stages of designing a magazine concept for a client, taking the printed version and adding animated and interactive content, it seems Flash would be the obvious choice, and something which I am reasonably skilled with.
If I build the Magazine app with Flash, will the app be able to download additional issues? if so please point to any resources on the subject if possible.
You can use the Packager for iPhone to get Flash content on an iOS device. However, you can't download compiled Flash files (.swf) to the iOS device and execute them after the app has been installed.
From the developer documentation:
Loader
In an iPhone application, you cannot
use the Loader.load() method. However,
you cannot run any ActionScript code
in SWF content loaded with the
Loader.load() method. However, you can
use assets in the SWF file (such as
movie clips, images, fonts, and sounds
in the library). You can also use the
Loader.load() method to load image
files
If you would like to use InDesign and some of the other tools that Adobe Makes, you can consider the so called Digital Publishing Suite which is a toolset that was used to make some of the iPad magazines such as Wired or Martha Stewart Living.

Can I develop my own objective-C Framework for Cocoa Touch Applications?

Is it possible to create an own obj-C Cocoa Touch framework which can be used by other developers? And furthermore can you protect this framework?
I've created templates for Xcode 4 that allow you to build universal iOS frameworks (which work in both device and simulator).
Once the templates are installed, you simply select "Static iOS Framework" when creating a new project and it does the rest. It also works with unit tests.
https://github.com/kstenerud/iOS-Universal-Framework
You can create a static library. There is an option in the XCode project chooser to do this. You'll have to distribute the compiled static library file and the header files to users of your library. Your actual implementation files (.m) do not need to be distributed.
GHUnit does a good job of this - packaging up the libraries for both simulator and device - so I recommend looking at this project. (I also recommend using this library for unit testing :-)
The frameworks in Objective C are typically just C / ObjC code and a bunch of classes, nothing amazingly special. As such, you can create your own if you'd like, and then just include that in your project when you build it. The iPhone doesn't care about the difference, it just knows to put all that code into your app, along with everything else.
Have a look at the Framework Programming Guide on Apple's website. It will get you started. Essentially what you'll do is create a Framework project in XCode and then go from there.
As for "protecting" your framework, I assume you mean making your code unreadable. I'm not sure if and how you can do this, but perhaps Apple's guide will say something about it.
Yes you can create frameworks for use with Cocoa Touch.
However there are these caveats:
has to be a statically linked libary, no dynamic loading (dyld) for us
should be a combined (lipo) library for i386 (simulator), arm6 and arm7
you need to hack a bundle project into a framework
you should embed (small and few) images into the library so that the developer does not have to mess around with resources but just drags/drops it into his project
... or if you have large and many images build a bundle with these
I have guides for these things on my site.
1+2 = http://www.drobnik.com/touch/2010/04/universal-static-libraries/
The other links you have to google because this site does not let me post more than one URL.
You could make a static library available as binary (i.e. rudimentary "protection") to third parties, but not a dynamic one, as Apple's App Store policy prevents dynamic linking.
Take a look at a worked example for static libraries given at
this site
If you're going to do it, in my opinion JSON.framework is a great example to follow. To hide/obfuscate the source code is a different story, and a different question entirely,
When creating a new project, navigate to iOS > Framework & Library > Cocoa Touch Framework, it's as simple as that. When you are successfully compile, .framework will be created under Products folder in XCode. Right click to show in Finder, and you can find the output.
It's unlikely this will work the way you want it to because the other developers won't be able to use your framework. This StackOverflow Question explains why.

iPhone: Native App with Locally Stored Webapp?

Is it possible to write a webapp, then embed it in a native app so it can be launched without data and sold through the app store?
The Pre makes it easy to reference files in the local file structure, so it's very easy to build a webapp (HTML, CSS and Javascript) and embed it into a native app.
Is it possible to take the same plain HTML, CSS and Javascript (no Mojo/Webos-specific code) and embed it in the same way into a native iPhone app? This would make it seem to the user as if the icon in the home menu launches a webapp, but the app can be accessed without any data and can be sold through the app store.
Thanks,
~J
Within my application, I have a complete HTML-based manual that I use a UIWebView to display. The HTML, CSS, and images are all stored locally in a Help directory within my application bundle. I simply load the first page using code like the following:
NSString *path = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:#"Help"];
NSURL *helpURL = [NSURL fileURLWithPath:[path stringByAppendingPathComponent:#"helpintroduction.html"]];
NSURLRequest *URLReq = [NSURLRequest requestWithURL:helpURL];
[webHelpView loadRequest:URLReq];
and everything loads and displays as if it were on a remote server.
To preserve the full directory structure of your HTML, etc. files, simply add those files to your Xcode project, dragging in directories where you can, and add a new Copy Files build phase. Make the destination Resources and the path whatever you want to use for the base of your web files (Help in the example above). Finally, drag all of the HTML, etc. resources you added to your project into this Copy Files build phase so that they end up bundled with your application.
I see no reason why this wouldn't work with more complex web applications, and I've seen no action by Apple against people doing this within their own applications.
I don't see why not, just give the UIWebView a baseUrl of your local stored bundle.
Look at PhoneGap (http://phonegap.com/)
I haven't used it but it may be a good solution for what you're trying to do.
Yes, it is perfectly doable. You just need to build the absolute path to your HTML files within your application bundle, using "file:///" as the protocol, and point the URL of a UIWebView to it. You can do a quick and dirty test using the iPhone OS simulator and writing something like "file:///foo/bar.html" on Safari.app, provided that HTML exists, it will load just fine.
The problem is packaging it. From what I can tell (and i could very well be totally wrong), apple just dumps all your files into one resources folder, regardless of directory structure in your project. So if you create a webpage that references images/logo.png and javascript/script.js, suddenly those files will be located in / instead of their respective folders. Given that, it might be feasible to create a web app with a completely flat structure from the start.
There's no technical reason I know of why this should be problem.
However, there's always the chance that Apple could reject the app for doing something like this — they certainly haven't been shy about rejecting apps for not "behaving properly" before, and web apps have some certain peculiarities which make them not feel like native apps.
Such a rejection could probably be resolved by resubmitting, since there's certainly no standard for this kind of thing, but it's certainly something to be aware of.
If you are not a coder and you are interested in iOS only, you can follow these steps:
Download xCode
Download simple web view app from https://github.com/nomtek/iOSWebViewApp
Open simple web view app within xCode
Add your HTMLs to the project file structure
Run your app and voila :)
This approach is good if you don't need access to any phone specific features, just a standard Web View. Loading time will be short as this approach doesn't load any extra libraries.