New Xcode Template (beta)
I've made a new Xcode template for turning Pythonista scripts into apps. It's based on the current beta of v. 1.6, so it's work-in-progress...
64-bit devices (iPhone 5s/6, iPad Air...) are supported now, but the 64-bit simulator isn't, so if you want to run your app in the iOS simulator, please choose a 32-bit device (e.g. iPad 2 or iPhone 5).
It's now easier to include pyui files, images etc. Just put them in the
Scriptfolder, next to
main.py, and they should be installed automatically when you build the project. Anything that is in this folder will be copied to the documents directory of the app, so you can access those files just like you would in Pythonista, and things like
ui.load_view()should "just work".
In previous versions of the template,
matplotlibwasn't supported, this should be fixed.
Please let me know if you have any problems getting this to work.
@OMZ: That's exactly what I have done.....and it is not my problem.
An example: in folder scripts I have three files (main.py, main.pyui, bes.db). All the files will be placed in the documents folder and can be accessed in iTunes. So far it is working well.
Now I replaced the bes.db via iTunes and start the program again. Surprise! The new bes.db will be overwritten with the old one and is gone. Another look into documents will show up the old version again.
Have I done something wrong?
Thanks so much for your effort. I can get an app to build, but when I try to add the .ipa to my device (ad hoc via iTunes) it says that it cannot be added because it's not a valid app.
I have a valid bundle ID, the info.plist looks OK, I can't figure out what it is. My PyCharm/Kivy-ios builds and techBASIC builds work fine.
FYI, I just replaced your info.plist with one from a working kivy-ios project and that works OK. Update: A newbie error I guess -- apparently the LS key LSRequiresIPhoneOS is required to build an app!
Love the new template! One thing: I can't seem to get the Pythonista 1.6/iOS 8 document picker in the
dialogsmodule to work. Launching it makes my app crash. Any suggestions?
Quick tip: one of the differences between the previous template and this latest one, is that the "Skip Install" flag in the Build settings is set to Yes. This means that when you create an App Archive for submitting to the store, it doesn't automatically export it to your Organizer Tool.
I haven't gone through the whole pipeline with this project template yet: script in Pythonista on the iDevice -> porting script to Xcode -> debugging in Xcode -> submitting to store -> distributing on store; it's not a priority for me at this point, but I have been playing with some of the settings. You've given us a good tool, @omz, to learn Xcode at a very superficial level, thanks. Anybody gone through the whole pipeline yet?
@dvader9: I've done ad hoc deployment to local iPads. The template works well on the few examples I've tried. The modifications I had to make to the info.plist file are the "LSRequiresIPhoneOS" key as I mentioned above and that "Skip Install" flag in the Build Settings that you mentioned.
The kids in my class will soon be creating apps for submission -- I'll let everyone know how that goes.
@OMZ: Thanks again for all your work!
I was this close to posting a bug report about how I couldn't run the vanilla template. But then I read the part about using a non-64 bit simulator.
Anyways. THIS IS AWESOME! I'm excited.
Oh yea - will this not work for UI generated using the 1.5 version of pythonista?
@omz This is probably a question directly for you.
When running an app built with the Xcode template, the launch screen/image is shown and then a screen similar to the Pythonista console is shown for a few seconds. After that the app starts.
I assume the console-like screen is loading up Python and all your code, but is there a way to overwrite this screen and possibly continue to show the launch screen/image defined in Xcode (or a custom image of some sort)? This would make the transition from launch screen to app much smoother looking.
I was also curious about the question above. Not having a smoother transition from splash screen to app could hurt overall ux. @andymitchhank have you tried dropping the splash screen? Do you still see the "load" page so to speak?
@jfryznke Just tested your idea and, unfortunately, the load page was still visible for a few seconds before the application loaded.
@andymitchhank hmmm, hopefully @omz has a solution. I haven't come across this anywhere else in the forums or in my own experience using pythonista/xcode. I haven't taken anything COMPLETELY through the pipeline yet, so I'm not sure if I would encounter a similar problem but I love to troubleshoot before I get there and help others troubleshoot to learn from their experience. Keep me posted on your progress and I'll update you if I have a similar issue.
In my other xcode experiences using a language other than obj c, I've never seen/heard something like this...it is intriguing.
I haven't worked with the most recent XCode template, but my experience with the prior one is the same. My splash screen shows up, then everything goes blank for a second or 2, then my interface appears.
I would really prefer that my splash screen remain visible till my first UI update takes place. Is there some way to force that to happen?
@jesse so do you just experience a blank screen for a brief moment or a page filled with code?
I feel that just a blank screen for a few moments is less of an issue than the problem @andymitchhank cited
Hi guys - I have some really strange behavior going on, and it's probably not related to the template, but I don't know so I thought I would see if you guys can draw on your immense wisdom to come up with some "obvious" answer. I don't want you guys to debug my code or anything, just please let me know if there's something obvious I'm missing.
So I have my app running inside pythonista 1.6 latest perfectly. I have it working in the template out of xCode as well. I'm using mysqldb.
At one point in my code I have a try except clause that attempts to cursor.execute("....") to create the table we'll be using and it excepts if that table already exists. (the table DOES already exist, and should except.)
Inside the pythonista app, it goes straight to the except clause like it should, "Table couldn't be created..." and proceeds as normal. Wierdness: Inside the xCode simulator however, it gets stuck at "....trying table creation"
AND HERE'S the SUPER WIERDNESS:
inside the simulator it will remain stuck trying to execute the database call UNTIL I RUN THE APP FROM THE PHONE. So as soon as I run the app on my phone it gets the simulator unstuck and moving past the except clause like it should...
huh. (I added the ip address of my mac to the amazon rds security group, but that doesn't seem to have any effect)
That's very strange...the iOS simulator should be completely disconnected from the physical iOS device. Just a few questions: when you run the script on your physical iOS device to unfreeze the simulator, are you running it within Pythonista or as a standalone app compiled with Xcode? Also, is your physical iOS device connected to the computer running the simulator? If so, is it a wired or wireless connection? Does your physical iOS device appear in Xcode as a potential target to run the template (with your script filled in) on alongside the iOS simulator? One last set of questions: this may sound dumb, but which of your devices (specifically your computer running the simulator and your physical iOS device) are connected to the Internet? Does your script connect to any server at all, or can it be run, with nothing disabled, when completely offline? Does your script use Bluetooth at all, perhaps with the
cbmodule in the Pythonista 1.6 beta? This may seem like a lot to ask for, but I honestly have no idea what could possibly make something like this happen, so I want to narrow down the possibilities as much as, well, possible (I can't possibly think of a possible synonym for "possible" right now, so yeah).
Also, make sure to remember that @omz hasn't yet released a template for the latest Pythonista 1.6 betas (the old template doesn't support features like the
skmodules), and there might be under-the-hood changes that break other stuff between the old template and the new betas. Don't say I didn't warn you ;-).
On my iPhone 6 plus, it's running from within Pythonista. Internet access is necessary for the script - doesn't work at all if offline. It doesn't seem to matter whether the phone's connected through LTE or wifi - the behavior persists. The Mac is connected through wifi, and all network functionality works. No Bluetooth module being used.
Update: xCode Beta 7. Will try xCode 6 and see how it goes.
what sort of Internet access is required! standard web pages? how are you connecting ( urllib, requests, etc)?
might be worth sniffing the connection with, say. wire shark to see what is different, for example a different user agent or something else, or if for example the simulator is duplicating the mac address, etc, or otherwise confusing your router. try turning off your firewall.
@omz: You could update the readme, now you don't need a PAID dev license to run on an actual device.
ld: -no_compact_unwind and -bitcode_bundle (Xcode setting ENABLE_BITCODE=YES) cannot be used together
clang: error: linker command failed with exit code 1 (use -v to see invocation)
This only occurs when building for my iPad mini, no problem building for the iPad 2 simulator. How do I fix this?
Had to go into build settings and set "enable bitcode" to "no"