Working with the native.newTextField() tonight and I needed a way to see the field in the simulator for easy positioning. Out of the box this is not available within the Corona SDK simulator, but thanks to this post by Jon Beebe it got me thinking... Can we just "overload" the native.newTextField() method and Hi-Jack it when we are in the simulator and instead draw a rounded edge rectangle on the screen for the sake of viewing and positioning things? Well, yes we can!
Let me walk you through it... I threw a simple example together to demonstrate this. (I'll keep it as small as possible, you will also need the ui.lua file from Corona examples to run this example, the other two files you need are at the bottom of the post)
In the main.lua file we simply add a label and a text input field (which will not display in the simulator without requiring in the "hijacks.lua" file)
The magic is in overloading the native.newTextField) method to do something different when we are in the simulator, but I want it to behave as normal when running on a device. Don't let the box.setTextColor declaration in the hijacks file scare you, this is just a placeholder basically because I happen to be setting the text color in my main.lua file for the text input field. This declaration accommodates this working in simulator mode as well as a device build without me having to toggle things or comment out things, etc. Of course, there's other tricks for capturing text input as this still won't do that, it's just for visual representation and positioning of things. For my release build I will just comment out the requires("hijacks") line and away I go!
main.lua
<code>
require("hijacks")
local ui = require("ui")
local function init()
local g = display.newGroup()
local background = display.newRect(0,display.screenOriginY, display.contentWidth, display.contentHeight-display.screenOriginY)
background:setFillColor(111, 111, 255)
g:insert(background)
-- Handler for the native keyboard
local fieldHandler = function( event )
-- Hide keyboard when the user clicks "Return" in this field
if ( "submitted" == event.phase ) then
native.setKeyboardFocus( nil )
end
end
local label = display.newText( "Location: ", 10, 252, native.systemFont, 18)
label:setTextColor(255,255,255)
g:insert(label)
-- A native text input field (requires XCode Simulator build or device build)
inputField = native.newTextField( 100, 252, 200, 24, fieldHandler )
inputField.font = native.newFont( native.systemFont, 20 )
inputField.text = "Papillion, NE" -- example of searchable location
inputField:setTextColor( 45, 45, 45 )
g:insert(inputField)
end
init()
</code>
hijacks.lua
<code>
module(..., package.seeall)
local priorNativeNewTextField = native.newTextField
native.newTextField = function(left, top, width, height, listener)
local box
if system.getInfo( "environment" ) == "simulator" then
box = display.newRoundedRect(left, top, width, height, 12)
box.setTextColor = function(...)
end
else
box = priorNativeNewTextField(left, top, width, height, listener)
end
return box
end
</code>
Showing posts with label Corona SDK. Show all posts
Showing posts with label Corona SDK. Show all posts
Friday, July 29, 2011
Tuesday, July 12, 2011
Getting your Bundle ID correct for App Store Submission using Corona SDK
My first app submission got bounced back for one simple reason:
3.4: App names in iTunes Connect and as displayed on a device should be similar, so as not to cause confusion
This is a pretty easy thing to screw up so I attempted to document the correct way to align your App name and Bundle ID so you can avoid getting bounced back like I did...
Step 1 - iTunes Connect
As soon as you know the name of your next app, you should go create a new App ID in your iTunes connect account so you can get that name reserved.
3.4: App names in iTunes Connect and as displayed on a device should be similar, so as not to cause confusion
This is a pretty easy thing to screw up so I attempted to document the correct way to align your App name and Bundle ID so you can avoid getting bounced back like I did...
Step 1 - iTunes Connect
As soon as you know the name of your next app, you should go create a new App ID in your iTunes connect account so you can get that name reserved.
In this example I gave it an App ID of "Cool App", choose how you want the App ID Prefix created and finally set the App ID Suffix to "com.domainname.coolapp"
App ID - this is how your App is going to be searched and displayed to users
App ID Prefix - this gets generated for you based on your provisioning profile being used
App ID Suffix - reverse DNS pattern to further uniquely identify this application
Piece of cake, no go get your application created and ready to upload!
Once you have filled in the remaining information about your application and you are ready to upload it (complete this process in iTunes Connect and your app is "Waiting for Upload" you are ready to continue...
Step 2 - build.settings
Before creating our deployment build, we need to add a couple of entries into the build.settings file, based on the information we put into iTunes Connect above...
These entries assure that the .zip package that gets submitted by Corona will match up with the expectations of the iTunes Connect information.
Now we are ready to build our deployment package, on to the last step...
Step 3 - Corona
This step is a bit tricky to me, and admittedly I don't know if it is 100% correct, however it is working for me and generating expected result in the App Store and the display device so if you have a better way please let me know!
Notice that in this dialogue for "Application name" I entered the reverse DNS Bundle ID from the iTunes Connect data.
My guess is that what happens is that Corona builds the Bundle ID based on the "Application name:" field in this dialogue box. When I attempted to put in the App ID Description (IE Common name) of "Cool App" you will get a deployment upload error from Corona stating that your package doesn't match anything that iTunes Connect is expecting from you (based on my example here), but I still ran into a scenario where my package name passed the check but I was missing the Display Name entry in the build.settings that we did above. This ultimately gets you the 3.4 rejection.
That's how it worked for me, so I hope it helps you! Also, if I have made an error of if you know of another way to configure this data please let me know, but this process successfully got my application through the review and onto the market with the correct names after first getting rejected for this reason...
And just to clarify, in this example the final .zip file that gets uploaded to iTunes Connect would be called com.domainname.coolapp.zip NOT coolapp.zip
Don't let a poor package name get you rejected and sent back around the review cycle!
Good Luck
--Croisened
Monday, July 4, 2011
My Corona SDK Quick Reference Items
This is just a quick list of reminders and tips that I look at when working on a project...I have these printed out, scribbled and post-it noted all over my desk so i figured I would make this post and clean up my workspace along the way. You might find them useful...or not. :)
Common Screen Resolutions (Portrait)
iPod Touch - 320x480
iPhone 3G - 320x480
iPhone 4G - 640x960
iPad - 768x1024
Droid Incredible - 480x800
Droid X - 480x854
Evo - 480x800
XOOM - 800x1280
Gestures to account for, or not: Tap, Drag, Flick, Swipe, Double Tap, Pinch Open, Pinch Close, Touch and Hold, Shake
Apple recommended minimum tappable size of a UI item: 44x44 points
Icons needed to support an Apple and Android deployment - (Start at a 512x512 image size, because you are going to need this for app submission, make all these smaller ones from that so you don't end up with a blurry/stretched 512x512 when you are all done - or used SVG or vector of course)
Some optimization tips:
Apple Human Interface Guidelines:
http://developer.apple.com/library/ios/#DOCUMENTATION/UserExperience/Conceptual/MobileHIG/Introduction/Introduction.html#//apple_ref/doc/uid/TP40006556-CH1-SW1
Android Guidelines:
http://developer.android.com/guide/topics/fundamentals.html
That's a start, this cleared a ton off my desk! What do you have laying around? Send me anything to add to this list or post your own...
Croisened
Common Screen Resolutions (Portrait)
iPod Touch - 320x480
iPhone 3G - 320x480
iPhone 4G - 640x960
iPad - 768x1024
Droid Incredible - 480x800
Droid X - 480x854
Evo - 480x800
XOOM - 800x1280
Gestures to account for, or not: Tap, Drag, Flick, Swipe, Double Tap, Pinch Open, Pinch Close, Touch and Hold, Shake
Apple recommended minimum tappable size of a UI item: 44x44 points
Icons needed to support an Apple and Android deployment - (Start at a 512x512 image size, because you are going to need this for app submission, make all these smaller ones from that so you don't end up with a blurry/stretched 512x512 when you are all done - or used SVG or vector of course)
- Icon@2x.png (114x114)
- Icon-72.png (72x72)
- Icon-hdpi.png (72x72)
- Icon.png (57x57)
- Icon-mdpi.png (48x48)
- Icon.ldpi.png (36x36)
Base config.lua file: (This is my basis for supporting Dynamic Image Resolution )
application =
{
content =
{
width = 320,
height = 480,
scale = "zoomStretch",
fps=60,
imageSuffix =
{
["@1x"] = 1.5,
["@2x"] = 2,
["@3x"] = 2.4,
}
}
}
Base build.settings file:
settings =
{
android =
{
versionCode = "1"
},
orientation =
{
default = "portrait",
supported =
{
"portrait",
},
},
iphone =
{
plist =
{
UIPrerenderedIcon = true,
UIApplicationExitsOnSuspend = true,
CFBundleIconFile = "Icon.png",
CFBundleIconFiles = {
"Icon.png",
"Icon@2x.png",
"Icon-72.png",
},
},
}
}
Some optimization tips:
- Get Rid of Blurry Text For Good!
- Definitely evaluate Director 1.3 and see if it fits your needs! If it does throw Ricardo a few bucks, this is a great jump start to a project!
- More tips from base2solutions
- Check your FPS
Apple Human Interface Guidelines:
http://developer.apple.com/library/ios/#DOCUMENTATION/UserExperience/Conceptual/MobileHIG/Introduction/Introduction.html#//apple_ref/doc/uid/TP40006556-CH1-SW1
Android Guidelines:
http://developer.android.com/guide/topics/fundamentals.html
That's a start, this cleared a ton off my desk! What do you have laying around? Send me anything to add to this list or post your own...
Croisened
Saturday, April 9, 2011
Setting up iMac for Mobile development with Corona SDK
I have officially made the move to MAC, of course I still use my Windows stuff on a VM utilizing parallels, but this post is about the feat of strength to stand up my mobile development environment on this new foreign machine to me and it ends with a successful deployment to my Android phone...
My main reasons for making is the switch is that I have decided on using Corona SDK for my mobile middleware. I have done native Android development, but to pick up yet another language to port to iOS is just not very appealing. With Corona, I can use Lua scripting and write my code once and deploy to both Android and iOS - perfect!
The toolsets I use:
My main reasons for making is the switch is that I have decided on using Corona SDK for my mobile middleware. I have done native Android development, but to pick up yet another language to port to iOS is just not very appealing. With Corona, I can use Lua scripting and write my code once and deploy to both Android and iOS - perfect!
The toolsets I use:
- Eclipse
- Helios edition
- Android SDK
- Java Runtime
- LuaEclipse (Lua 5.1 plugin for Eclipse)
- XCODE - developer tools for mac and needed for iOS development
- Corona SDK
Lets begin...
- Install Eclipse (This step is pretty straight forward, no surprises, just pick the version you want)
- To get Lua integrated with Eclipse, you have some hoops to jump through, i relied heavily on this post which was quite helpful. LuaEclipse The main catch is that you are going to need XCODE installed in order to be able to use macports to grab the Lua interpreter and profiler that you will subsequently setup within Eclipse. (Keep in mind if you are working with Corona, any text editor will do since their are limited editors with text highlighting and auto completion for te Corona API's, but for my taste I want to continue working within Eclipse as much as possible in case I go native on android I'm good to go.) Again, trying to use as many common tools and write once approaches as possible to get on both Android and iOS.
- Pull down the Android SDK - not bad on this step just follow the steps on Android SDK Install Guide
Gotcha's....
- There's a step after installing luarocks from macports where you need to allow luarocks to run as a privileged user - this was foreign to me and later I found to just get to the file in Finder and click the little pad lock and enter my master password, change the permission and lock it back down - not too bad
- This is more of a Corona thing, but when I got my first application published to my phone I couldn't get the correct icon to display in the applications menu, this is because they need to be correctly sized and named beginning with Android 2.2 as such:
- Icon-hdpi.png 72x72 pixels
- Icon-mdpi.png 48x48 pixels
- Icon-ldpi.png 36x36 pixels
- Also, for earlier versions you need an icons folder in your solution and just an icon.png file of 48x48
Well that's it for now, after a couple hours pulling all this together I have a nice workflow environment that I feel at home with to code for both Android and iOS utilizing the Corona SDK for emulating and building and Eclipse for my Lua script editing.
Subscribe to:
Posts (Atom)