Hello,
I'm trying to understand how to create iOS libraries for extensions. Before trying to create a real extension, I wanted to learn something more about iOS and I created a project on Xcode. In just a day I created a project that is able to display iAds on iPhone 4, iPhone 5 and iPad's screens, both portrait and landscape with the banner that adjust its width and height automatically. Today I started to work on an extension for Stencyl, but it seems I am doing something wrong when trying to run the "build" script.
Actually I didn't run that script, I have just modified it and copied the modified file in the Terminal. This is my script:
mkdir /Users/user-name/Desktop/Simone/Programmi/StencylWorks-full/plaf/haxe/extensions/ads/ndll
mkdir /Users/user-name/Desktop/Simone/Programmi/StencylWorks-full/plaf/haxe/extensions/ads/ndll/Android
mkdir /Users/user-name/Desktop/Simone/Programmi/StencylWorks-full/plaf/haxe/extensions/ads/ndll/iPhone
haxelib run hxcpp Build.xml -Dandroid
haxelib run hxcpp Build.xml -Diphoneos
haxelib run hxcpp Build.xml -Diphoneos -DHXCPP_ARMV7
haxelib run hxcpp Build.xml -Diphonesim
I think that the problem isn't with the script itself. When I try to run it in a original ads extension, it works and creates all the libraries. but when I try to run the same script inside my extension it doesn't work. There are lot of pages filled with what I think are errors and these are the last lines:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/System/Library/Frameworks/CFNetwork.framework/Headers/CFHost.h:41: error: expected declaration before end of line
Called from ? line 1
Called from BuildTool.hx line 1310
Called from BuildTool.hx line 580
Called from a C function
Called from BuildTool.hx line 617
Called from BuildTool.hx line 748
Called from BuildTool.hx line 782
Called from BuildTool.hx line 200
Uncaught exception - Error : 1 - build cancelled
My project is running fine in xcode without a single error or warning. I copied the .m and .h files in the extension and ran the script. I had to modify the source code of the .m file because it was giving me some errors when trying to run the script (the modified file still works in xcode), but after resolving those errors (which outputted only a few lines in the terminal when trying to run the script), a lot of new errors came up. While the first errors were related to the .m file, the second ones are something completely out of my reach. I would like to know if there are relevant differences between building something with xcode or with the "build" script.
Thank you!
Update 1
How I solved my problem
Actually I didn't solve my problem. I restarted the project from the beginning and now I am getting no errors. There are some differences between this new project and the original one, but I still don't understand why I didn't succeed in compiling the first one... (Restarted Xcode? Restarted the computer? Other?)
My new issue
Now I am facing a new strange issue: the extension I am working on seems to be working well except for the fact that the banner won't show up. In the Xcode project everything works ok, both in portrait and in landscape, while in Stencyl there are no errors, but there are no banners as well!...
I tried to isolate the problem and filled the code with NSLog(), but I couldn't find anything... In both Xcode and Stencyl, the first thing to do is to create the "bannerview", then place it properly (hidden outside of the screen), then wait for an ad to be loaded and move the banner in the right position. When there are no ads, the banner has to be hidden (Apple's policies). As I said, everything works well in xcode and the logs tell me a lot of information about what is going on. The fact is that also in Stencyl everything seems to work well: the logs tell me that the bannerview is created, positioned in the right place, waits for the ad and, when the ad is loaded, it moves in the right place. The problem is that I see no banners... How is that possible?
I would be very happy if someone could enlighten me on the matter. I am running the game on the iPhone Simulator with iOS 6.1 (in xcode it works well both with iOS 5.1 and 6.1).
Update 2
Hi, I'm here again! I continued to work on this extension and I'm glad I made some progress. Now I am able to make a banner appear, but there are some orientation issues... My guess is that there is something that is not working as it should in Stencyl's implementation of Haxe NME, but I could be wrong since I am a beginner (and I hope I am wrong).
In portrait mode, everything is working as it should on the iPhone. The problem appears when I test the extension in landscape mode where ad banners appear at the wrong position and orientation: they appear just like when the game is in portrait, but with the iPhone in landscape mode. At first I thought I was making some kind of mistake somewhere in the code and I decided to make some researches on the matter. While reading I found an interesting thing: even if the iPhone is in portrait mode, if the game is designed to use a 480x320 (width and height) screen, the iPhone simulator automatically rotates to use landscape mode, but the game still thinks that the iPhone is in portrait mode. So basically the iPhone simulator shows an iPhone in landscape (you can pull down the notification center from the longer, 480px, side), but if I ask to the game "what's your orientation?", its answer would be "portrait".
So I did: here is a part of the code in Ads.hx.
if((Stage.getOrientation() == Stage.OrientationLandscapeLeft)||(Stage.getOrientation() == Stage.OrientationLandscapeRight))
{
orientation = 0;
}
else if(Stage.getOrientation() == Stage.OrientationPortrait)
{
orientation = 1;
}
And even if the game is in landscape, "orientation" is always 1, which means that the game tells me it is in portrait. Moreover if I try to get the screen width and height they are switched (if the game were in landscape, they would have been switched, but if it is in portrait they are fine). What I am trying to say is that eben if the game looks to be in landscape, it is only a "masked" portrait mode.
At the end of the post there is an image that shows the ad banner placed at the wrong position, so you can understand better what is happening. As rob1221 suggested, this orientation bug (if it exists) can be the reason for Game Center bugs, which are, as Jon himself stated, a mistery.
I have also updated the extension folder (zip) at the end of the post.
List of possible causes:
- iOS Simulator running an old version (4.3)? No, Simulator version is ok.
- X and Y coordinates are different between Xcode and Stencyl?
- Possible orientation bug in Stencyl's implementation of Haxe NME?
I have attached three files at the end of the post:
1) The Xcode project (Look for the Ads.mm and the Ads.h files).
2) The extension folder (Look for the differences with the Xcode project: just a line of code).
3) A simple test game (Touch the screen to make the ads appear/disappear).
Thank You for reading this long and probably boring post!