Building an extension for iAds

Abliblablobla

  • *
  • Posts: 524
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!

« Last Edit: June 20, 2013, 10:40:59 am by Abliblablobla »
.: BuruBuru :.

Jon

  • *
  • Posts: 17523
You need to rename the .m files to .mm.

Abliblablobla

  • *
  • Posts: 524
Thank you for your answer, but unfortunately it didn't resolve my issue...

Both my files (.h and .mm) are being compiled without errors in Xcode, but I am experiencing the same problems when trying to create the libraries I need. The last lines that appear in the Terminal are:

from ./common/ExternalInterface.cpp:10:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.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


I have the latest version of Xcode and I have iOS SDK 6.1 and 5.1 (but I think it's trying to build the libraries against 6.1). If the problem is at line 10 of ExternalInterface.cpp, in that line there is only #include "Ads.h" and nothing else.

Any idea? Help would be appreciated a lot!

Thank you!
.: BuruBuru :.

Jon

  • *
  • Posts: 17523
If you don't mind, could you post up the source to the extension (as a ZIP file would be fine)? I could try compiling it on my end.

Abliblablobla

  • *
  • Posts: 524
No problem,

I have attached the Xcode project that contains both the Ads.mm and Ads.h files. If you try to compile the project with it should successfully build. The ExternalInterface.cpp and Ads.hx files shouldn't need big changes. In the .mm file there is code specific for iOS SDK 6.0 or later (6.1) because iAds implementation slightly changed in the new major version of the SDK, so I think you should have the latest version of the SDK. I added some comments so that if someone wants to take a look at the code it should be simple to read and understand.

Thank you for your support!

Edit: Look at the first post.

« Last Edit: May 21, 2013, 01:46:04 pm by Abliblablobla »
.: BuruBuru :.

Abliblablobla

  • *
  • Posts: 524
Any news on this?
.: BuruBuru :.

Jon

  • *
  • Posts: 17523
Not yet - I've had a lot of different commitments to deal with today.

Abliblablobla

  • *
  • Posts: 524
I have updated the first post.

I solved my first problem and now I have a new and very strange issue... Look at the first post for more details. I hope to get a little help on this one, but I understand that there are more important and general issues you are tackling with great results (e.g. memory leaks and iPhone 5 support for 2.2), so I can wait a while. :)
.: BuruBuru :.

rob1221

  • *
  • Posts: 9421
No errors?  I see this when I try to build (no changes made to files).

Abliblablobla

  • *
  • Posts: 524
Thank you rob1221 for spending some time to look at my posts.

I took a look at the text file Ads Errors.txt. Actually I don't see any error in that file... There are some warnings but they are warnings and not errors. If you compile the same files in Xcode you can have a better understanding of the meaning of those warnings, but they don't prevent you from compiling the project. Moreover at the end of your txt file, it is stated "process complete" and not something like "build canceled" (the more common phrase when something went wrong when compiling the project using Terminal). One of the last lines is:

ranlib ../ndll/iPhone/libads.iphonesim.a

which says that the libads.iphonesim.a has been updated and if you look at that file in extensions/ads/ndll/iPhone, it will probably have today's date.

Most of the warnings are about some identifiers that are being deprecated from iOS 6.0 but are required for backward compatibilty (iOS 5.x).

I don't know if my explanation was clear... I hope you understand it! I will be back on this project as soon as I have some spare time (probably in two or three days).
.: BuruBuru :.

rob1221

  • *
  • Posts: 9421
The Origin Y is being set outside of the screen (tested in landscape using both top and bottom ads).  I noticed you disabled the Stencyl event ad listeners, so maybe those are what Stencyl uses to position the ad?

EDIT: Actually I see the Origin Y is set based on the ContentFrame height and width, which in my tests is wrong.  The height says 480 and the width 320, when the opposite is true.

I tested again in portrait which had the correct values, but the ad still didn't show, so something else is wrong.  I'm thinking there is some conflict with what Stencyl is doing, since the default ad extension does not include the .mm and .h files you added.

« Last Edit: June 18, 2013, 06:11:08 pm by rob1221 »

Abliblablobla

  • *
  • Posts: 524
I think I understood what's wrong with iAds. There are two things:

1) The first thing is that if we want to make a change to a UI element we need to make something like Run Thread On UI which is needed for Android.

2) I think that there may be a bug with orientation. In iOS even though we set Landscape in Stencyl's Settings, the game is in portrait mode. This can be seen, as you have noticed, when I try to create a content frame that matches the screen bounds frame. If the game is in portrait, the frame has h:480 and w:320, but when the game is in landscape it still has h:480 and w:320.

I will investigate a bit more later today and report my results.
.: BuruBuru :.

rob1221

  • *
  • Posts: 9421
I wonder if there are some underlying orientation issues causing most of the problems with iAds and Game Center because those problems don't happen on every orientation on every device.

Abliblablobla

  • *
  • Posts: 524
Added Update 2 to the first post!
.: BuruBuru :.