Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

iAd Plugin for Unity

Discussion in 'iOS and tvOS' started by jonaphin, Jul 8, 2010.

  1. kinzia

    kinzia

    Joined:
    Aug 14, 2010
    Posts:
    18
    Hi jonaphin

    Just import and replace the new plugin in my existing project but it does not work

    I get this error on Xcode console

    Ad Loading Error: Error Domain=ADErrorDomain Code=3 "The operation couldn’t be completed. Ad inventory unavailable" UserInfo=0xbafbf0 {ADInternalErrorCode=3, NSLocalizedFailureReason=Ad inventory unavailable}

    But I can confirm that the new plugin is work on my new empty project. Did I made some wrong setting on my existing project?
     
  2. jonaphin

    jonaphin

    Joined:
    Dec 31, 2008
    Posts:
    209
    Hi Kinzia,

    This error does happen, as iAd errors are injected by Apple into test sessions; but it just should not happen all the time.
    Try launching your app again, several times, and see if the occurrence is consistent.
     
  3. Hodofca

    Hodofca

    Joined:
    May 9, 2010
    Posts:
    83
    I've tried to make blank test app with demo assigned and it worked just once. I dont know if it is because of iad.framework and CoreGraphic.framework are red color in xcode or another problem. I was supprised that it worked just once without those frameworks. Should i get them? Where i can find it?
     
  4. jonaphin

    jonaphin

    Joined:
    Dec 31, 2008
    Posts:
    209
    You need to build your application using the iOS SDK 4.1, Hodofca.
     
  5. bakno

    bakno

    Joined:
    Mar 18, 2007
    Posts:
    595
    Great work!

    Purchased it and downloaded it. However on my Unity 3 Pro game it does not seem to work.

    Checking the Xcode project, I don't see the frameworks that should be added.

    Please help
     
  6. jonaphin

    jonaphin

    Joined:
    Dec 31, 2008
    Posts:
    209
    Hi Bakno,

    Please check that the permissions are set to read/write/execute for your user on the postprocessbuildplayer files. That might be the problem. Also, it may be a good idea to review the previous posts, just to check if your issue has been dealt with already :)

    Also, you may want to start a fresh project and import the package there, just to make sure the problem is indeed related to the plugin setup.
     
  7. bakno

    bakno

    Joined:
    Mar 18, 2007
    Posts:
    595
    Hello jonaphin

    I revised all posts on this thread before I wrote mine.

    Now I created a test project and found that if you activate any "Stripping Level" the ads are not shown on the application.

    Changing the postprocessbuildplayer files privileges did not solve the lack of frameworks additions.

    If possible, I would prefer to avoid the last option to export and import into a new project. Do you have any other suggestion?

    Regards
     
  8. jonaphin

    jonaphin

    Joined:
    Dec 31, 2008
    Posts:
    209
    I am not sure this is proper behavior on Unity's end. I'll have to check. What seems to happen according to what you are telling me is that the stripping level option influences the order of the arguments being passed.

    Alternatively, it may have to do with my python script not escaping the commands correctly. I'll check the postprocessbuildplayer scripts when I get home.
     
  9. bakno

    bakno

    Joined:
    Mar 18, 2007
    Posts:
    595
    Hello jonaphin

    Exporting the whole project as a Unity package and then importing it into a new project did not work for me either.

    I don't understand what can be causing this. But basically, the XCode project does not have the iAd and CoreGraphics frameworks added.

    Adding them manually does not work either. There are obviously other modifications not being performed by the postprocessbuildplayer.

    Please help
     
  10. jonaphin

    jonaphin

    Joined:
    Dec 31, 2008
    Posts:
    209
    Let's take this off-board. We'll post the solution to your problem to have users that may have a similar problem benefit from the solution
     
  11. bakno

    bakno

    Joined:
    Mar 18, 2007
    Posts:
    595
    Thanks jonaphin

    Please let me know when the solution is posted.

    Great product! Congratulations.
     
  12. bakno

    bakno

    Joined:
    Mar 18, 2007
    Posts:
    595
    Hello jonaphin

    The problem seems to be related to the post-processing order. I mean that Unity has its own post-processing operations to create the XCode project, and somehow the order in which both post-processing functions are called is not always the same. Maybe because the Unity operations take longer than anticipated. Just wild guessing.

    I am just throwing crazy ideas here. But if this is the case, do you think it is possible to create a post processing script that we can call independently from Unity? It may not be an elegant solution, but a temporary workaround.
     
  13. jonaphin

    jonaphin

    Joined:
    Dec 31, 2008
    Posts:
    209
    Hi bakno,

    You can do this of course. The postprocessbuildplayer script is open, and if the default workflow causes trouble for your app, you may rewrite parts of it to accommodate your needs.
     
  14. mikolo

    mikolo

    Joined:
    Nov 27, 2009
    Posts:
    249
    very cool plug in..thanks
     
  15. rocket5tim

    rocket5tim

    Joined:
    May 19, 2009
    Posts:
    242
    Has anyone managed to get this iAds plugin and OpenFeint working together yet?
     
  16. MikeHergaarden

    MikeHergaarden

    Joined:
    Mar 9, 2008
    Posts:
    1,027
    Can this be used on iPad already (weakly linked)?

    I'm trying to do so but get the following error (XCODE console):
    Target device 3.2. using SDK 4.1. I used Unity->Build and then manually ran XCODE.
    Where should I look for the problem?

    EDIT: Fixed, I had to edit the library to Weak linking manually. See Target->Unity iPhone properties of the iAd framework
     
    Last edited: Oct 28, 2010
  17. MikeHergaarden

    MikeHergaarden

    Joined:
    Mar 9, 2008
    Posts:
    1,027
    One question remains: the iAd framework keeps being reverted to 'required'. How can I ensure it's weak linked? Where/how does this plugin include the iAd framework?

    I guess it would do no harm to have it weak linked per default.
     
  18. rrvs331

    rrvs331

    Joined:
    Aug 16, 2010
    Posts:
    51
    @Danneman
    I have implemented iAds in one of my non-unity apps, and I get .15 per click, but a fill rate of less than 50%.
     
  19. jonaphin

    jonaphin

    Joined:
    Dec 31, 2008
    Posts:
    209
    I'll see if I can help the "required" to "weak link" in the next iteration, which should be in time for iOS 4.2 (and thus iPad compatibility).
     
  20. DF118

    DF118

    Joined:
    Apr 24, 2010
    Posts:
    9
    Hi Guys,

    I too am trying to integrate IAd with Openfeint enabled game, using iPhone 1.7. I'm using the PostprocessBuildPlayer_openfeint script posted a couple of pages ago, as well as the PostprocessBuildPlayer_iAd4Unity, and the PostprocessBuildPlayer kindly posted by jonaphin. I've also placed the iAd4Unity.prefab and AdBannerTop.prefab into my scene's hierarchy. The Unity console returns the following when I hit play on the editor:

    ShowBannerTop
    UnityEngine.Debug:Log(Object) (at /Users/build/builds/unity-iphone/iphone/Runtime/Export/Generated/BaseClass.cs:1679)
    iAd4Unity:RunCommand(String) (at Assets/Plugins/iAd4Unity.cs:73)
    iAd4Unity:ShowBannerWithPosition(BannerPosition) (at Assets/Plugins/iAd4Unity.cs:47)
    AdBannerTop:Start() (at Assets/Scripts/AdBannerTop.js:2)

    However the IAd.framework isn't appended to the project in Xcode when I build.

    I've amended my XCode project settings and Active target settings to Base SDK 4.1, with an iOS deployment target of 3.0 or 3.2, but no dice when append building again from Unity.

    Am I missing a trick here? Has anyone managed to get OF integration and this iAd plugin to integrate together?

    Thanks, any help on this would be greatly appreciated. My Lite app is currently waiting for review, but I'd love the opportunity to apply iAd.

    -DF
     
  21. DF118

    DF118

    Joined:
    Apr 24, 2010
    Posts:
    9
    Well, I have the iAd framework integrated with an Openfeint enabled project (I now only have one PostprocessBuildPlayer. I removed the PostprocessBuildPlayer_Openfeint and PostprocessBuildPlayer installed by the iAd plugin from the project, and renamed PostprocessBuildPlayer_iad4unity to PostprocessBuildPlayer), the script built okay:

    Build.log
    Code (csharp):
    1.  
    2. 0:/Users/xxx/Desktop/xxx 1.0 WithOpenfeint/Assets/Editor/PostprocessBuildPlayer 1:/Users/xxx/Desktop/xxx 1.0 WithOpenfeint/Unity Player 2:iPhone 3:  4:Personal Projects 5:xxx 1.0 WithOpenfeint 6:1024
    3.  
    But no iAds. I've taken a look at the appcontroller.h at your suggestion jonaphin, it's being called by this, yeah?

    Code (csharp):
    1.  
    2. @interface AppController : NSObject<UIAccelerometerDelegate, UIApplicationDelegate>
    3. {
    4.     InGameAdViewController *adViewController;
    5.     UIWindow*           _window;
    6. }  
    And an additional reference to adViewController in the .mm. Can this be moved / modified or messed with in any way to force the iAds to appear? I'm a little stumped.
     
    Last edited: Oct 31, 2010
  22. jonaphin

    jonaphin

    Joined:
    Dec 31, 2008
    Posts:
    209
    Let me know what the errors are in the Xcode console (cmd + shift + r) after you launch your app from it. There should be errors (inventory and what-not) but not all the time.
     
  23. DF118

    DF118

    Joined:
    Apr 24, 2010
    Posts:
    9
    Hi jonaphin, thanks a lot for your reply.

    Here you go.

    Code (csharp):
    1.  
    2. Loading program into debugger…
    3. Program loaded.
    4. target remote-mobile /tmp/.XcodeGDBRemote-7003-50
    5. Switching to remote-macosx protocol
    6. mem 0x1000 0x3fffffff cache
    7. mem 0x40000000 0xffffffff none
    8. mem 0x00000000 0x0fff none
    9. run
    10. Running…
    11. [Switching to thread 11523]
    12. [Switching to thread 11523]
    13. continue
    14. warning: Unable to read symbols for "/Library/MobileSubstrate/MobileSubstrate.dylib" (file not found).
    15. warning: Unable to read symbols for "/Library/MobileSubstrate/MobileLoader.dylib" (file not found).
    16. 2010-11-01 19:50:08.578 CatAttackLite[196:307] MS:Notice: Installing: com.SJSRDHV2K8.CatAttackLite [CatAttackLite] (550.32)
    17. 2010-11-01 19:50:08.741 CatAttackLite[196:307] MS:Notice: Loading: /Library/MobileSubstrate/DynamicLibraries/Activator.dylib
    18. warning: Unable to read symbols for "/Library/MobileSubstrate/DynamicLibraries/Activator.dylib" (file not found).
    19. 2010-11-01 19:50:08.872 CatAttackLite[196:307] MS:Notice: Loading: /Library/MobileSubstrate/DynamicLibraries/Backgrounder.dylib
    20. warning: Unable to read symbols for "/Library/MobileSubstrate/DynamicLibraries/Backgrounder.dylib" (file not found).
    21. warning: Unable to read symbols for "/Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.0.1/Symbols/usr/lib/libsubstrate.dylib" (file not found).
    22. 2010-11-01 19:50:09.056 CatAttackLite[196:307] MS:Notice: Loading: /Library/MobileSubstrate/DynamicLibraries/IntelliStatusIconsView.dylib
    23. warning: Unable to read symbols for "/Library/MobileSubstrate/DynamicLibraries/IntelliStatusIconsView.dylib" (file not found).
    24. 2010-11-01 19:50:09.231 CatAttackLite[196:307] Initializing IntelliStatusBarIcons v0.93
    25. 2010-11-01 19:50:09.239 CatAttackLite[196:307]  Initialized listener for icon updates
    26. 2010-11-01 19:50:09.607 CatAttackLite[196:307] MS:Notice: Loading: /Library/MobileSubstrate/DynamicLibraries/libstatusbar.dylib
    27. warning: Unable to read symbols for "/Library/MobileSubstrate/DynamicLibraries/libstatusbar.dylib" (file not found).
    28. Unity runtime class registered 0x66b744
    29. Unity runtime class registered 0x6767c0
    30. ...
    31. ...
    32. Unity runtime class registered 0x704bf4
    33. Unity runtime class registered 0x706818
    34. 2010-11-01 19:50:09.750 CatAttackLite[196:307] -> registered unity classes
    35. 2010-11-01 19:50:09.754 CatAttackLite[196:307] -> registered mono modules
    36. AudioStreamBasicDescription:  2 ch,  44100 Hz, 'lpcm' (0x00000C2C) 8.24-bit little-endian signed integer, deinterleaved
    37.            position - info.byteStart != info.byteSize (Filename: /Users/build/builds/unity-iphone/iphone/Projects/../Runtime/Serialize/SerializedFile.cpp Line: 760)
    38. position - info.byteStart != info.byteSize (Filename: /Users/build/builds/unity-iphone/iphone/Projects/../Runtime/Serialize/SerializedFile.cpp Line: 760)
    39. position - info.byteStart != info.byteSize (Filename: /Users/build/builds/unity-iphone/iphone/Projects/../Runtime/Serialize/SerializedFile.cpp Line: 760)
    40. position - info.byteStart != info.byteSize (Filename: /Users/build/builds/unity-iphone/iphone/Projects/../Runtime/Serialize/SerializedFile.cpp Line: 760)
    41.  
    42.  
    43. End Load File completely 393.184125
    44.  
    45. ShowBannerTop (Filename: /Users/build/builds/unity-iphone/iphone/Projects/../Runtime/Export/Generated/BaseClass.cpp Line: 1719)
    46.  -> force accelerometer registration
    47. 2010-11-01 19:50:11.946 CatAttackLite[196:307] Using OpenFeint version 8262010 (2.6.1). https://api.openfeint.com/
    48. -> applicationDidBecomeActive()
    49. 2010-11-01 19:50:13.551 CatAttackLite[196:307] OF[Presence]: Connection attempt number 1
    50. 2010-11-01 19:50:13.553 CatAttackLite[196:307] OF[Presence]: Spawning presence thread...
    51. 2010-11-01 19:50:13.562 CatAttackLite[196:8853] OF[Presence]: Presence thread started
    52. 2010-11-01 19:50:15.241 CatAttackLite[196:8853] OF[Presence]: Stomp client connected
    53.  
    iAd doesn't appear to be getting called in the above...?
     
  24. jonaphin

    jonaphin

    Joined:
    Dec 31, 2008
    Posts:
    209
    Thanks. It does not even reach the point where iAd is actually started.
    Are the library and frameworks (libiad4unity.a, CoreGraphics.framework, iAd.framework) present in the Xcode project?

    You may want to try importing the package on a brand new project and try it out, just to make sure that the problem is OF-project specific.

    Other people are having trouble integrating OpenFeint with it, so that could be the problem.
     
  25. DF118

    DF118

    Joined:
    Apr 24, 2010
    Posts:
    9
    Yep, all present and correct. Actually, CoreGraphics is already in the project, (seems to be duplicated now that iAd has compiled okay) it's required by Openfeint in order to work. Here's a list of the OF dependent frameworks:

    Is it possible that any of these could be killing it? Or do you think OF could be retaining some resource required by your plugin? I'm afraid I don't a lot about the way OF works.

    I've build a test project, and the iAd plugin works great. I'm looking forward to making use of it.
     
  26. jonaphin

    jonaphin

    Joined:
    Dec 31, 2008
    Posts:
    209
    Hi DF118,

    Unfortunately, I have 0 experience with OF myself, but you may want to read a few posts that were posted on the previous page or so, as some other users are currently sharing your frustration with OF/iAd.
    I do want to make this right, so if anyone has a working sample project with OpenFeint and wants to pass it forward, I'll do my due diligence and get this resolved once and for all. :)
     
  27. polsen

    polsen

    Joined:
    Nov 2, 2010
    Posts:
    11
    I have an iPad App which I'm thinking of putting Free and including iAds but need to know whether your plugin works with iPad? Please advise.
     
  28. jonaphin

    jonaphin

    Joined:
    Dec 31, 2008
    Posts:
    209
    Hi polsen,

    The iOS SDK 4.2 GM just came out an hour ago. What it means is that we should be able to have iAd on iPad this month (I think November 24).
    Now, you have to give me some time to update the plugin so it can run on iPad.

    As of today, no application on the iPad App Store has iAd running, as iAd is not compatible with the current iPad Operating System. This will change this month with iOS 4.2
     
  29. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    I so far found admob to be the most profitable ad revenue source.
     
  30. DF118

    DF118

    Joined:
    Apr 24, 2010
    Posts:
    9
    Here you go, have a look at this test Unity project including the XCode build. This just contains one scene with the OF and your iAd plugin. This includes Openfeint 2.6.1, was built with Unity iPhone 1.7.

    http://rapidshare.com/files/428553150/ad_and_of_test.zip

    Frameworks incorporated as before. This is very important- if you create a new build from Unity, make sure you append rather than replace. If you replace, you'll have to re-incorporate OF into the xcode build again (or restore from backup). Frameworks, bugfixes, all of it. This, as you can imagine, is a major pain.

    I look forward to hearing what you're able to come up with. Like I say, iAd would be great for my lite app, my game is dependant on Openfeint so I can't bin the latter.
     
  31. jonaphin

    jonaphin

    Joined:
    Dec 31, 2008
    Posts:
    209
    Hi DF118,

    The project fails to upload to my device. I believe it's due to the fact that my dev environment is iOS SDK 4.2.
    In any case, I've seen too many frameworks that were duplicated, and the iAd prefabs were not part of the test either. You may want to look into this.

    On another note, guys, the plugin has just been updated to work with iOS SDK 4.2 :)
    Rotations are back with a vengence!!

    Can anyone please test it on an iPad and let me know how that is going?

    Thanks guys!

    Edit: If you haven't received an email update in the next two hours or so, just email me :)
     
  32. travisloh

    travisloh

    Joined:
    Mar 24, 2010
    Posts:
    23
    i bought the plugin. Having an error as below unfortunately. Any ideas?

    "_ADBannerContentSizeIdentifierLandscape", referenced from:


    _ADBannerContentSizeIdentifierLandscape$non_lazy_ptr in libiad4unity.a(InGameAdViewController.o)
     
  33. jonaphin

    jonaphin

    Joined:
    Dec 31, 2008
    Posts:
    209
    Hi travisloh,

    Are you on the iOS SDK 4.2?
     
  34. travisloh

    travisloh

    Joined:
    Mar 24, 2010
    Posts:
    23
    yeah ios 4.2, sorry for the late reply. I can't seem to find a solution of the above error.
     
  35. jonaphin

    jonaphin

    Joined:
    Dec 31, 2008
    Posts:
    209
    Let's take this offline. Please email me your device specs (Type, OS version). Thank you!

    We'll post the solution on the thread for others to benefit :)
     
  36. polsen

    polsen

    Joined:
    Nov 2, 2010
    Posts:
    11
    Hi jonaphin ... any quick update on how the iPad integration of your iAds Plug-in is coming along since the release of 4.2 GM Seed?

    ... keen to buy and incorporate into my iPad App :)
     
  37. jonaphin

    jonaphin

    Joined:
    Dec 31, 2008
    Posts:
    209
    I haven't tested it on the iPad as I do not own one myself. Please feel free to let me know how it is working.
     
  38. mikolo

    mikolo

    Joined:
    Nov 27, 2009
    Posts:
    249
    hi, is there a solution to run OF and iAd together now?

    SDK 4.1 | Unity iPhone Pro 1.7 | OF 2.6
     
  39. jonaphin

    jonaphin

    Joined:
    Dec 31, 2008
    Posts:
    209
    Hi mikolo,

    Leepo got it to work apparently. You have to change it from "Required" to "Weak-Linked" in your project and you should be good to go.

    On another note, I will be pushing another update to the iOS SDK 4.2 version as soon as I'm able to test against the Apple servers. They seem to be having problems right now.
     
  40. mikolo

    mikolo

    Joined:
    Nov 27, 2009
    Posts:
    249
    sure? that would be great... but this sounds to much easy... i am not sure if you are right? Now i deinstalled again the iAd this moment.

    I want that both are also working. Wich framework i have to "weak"? libiad4unity.a? or iAd.framework?
     
  41. mikolo

    mikolo

    Joined:
    Nov 27, 2009
    Posts:
    249
    Hello how can i edit the postprocessbuildplayer file to use your code?
     
  42. jonaphin

    jonaphin

    Joined:
    Dec 31, 2008
    Posts:
    209
    Hi Mikolo,

    Use your favorite python text editor. If you do not have one, well use Notepad++ on Windows or TextMate on OS X. Don't forget to set the language/syntax highlighting to Python :)
     
  43. mikolo

    mikolo

    Joined:
    Nov 27, 2009
    Posts:
    249
    OK i changed the postprocessbuildplayer to "postprocessbuildplayer_openfeint!
    The PostprocessBuildPlayer_iAd4Unity and a new? PostprocessBuildPlayer was added when importing package.

    now i edit the PostprocessBuildPlayer with textmate and fill in following code:

    PHP:
    #!/usr/bin/perl


    # Post Process Build Player -- Master 
    # Unity Enhancement Pack
    #
    # Searches for other PPBP scripts and executes them. Make sure the other script
    # have a name suffix like "_EnhancementPack" or whatever.
    #
    # Rob Terrell, rob@stinkbot.com
    #

    use File::Glob ':glob';

    @
    files bsd_glob('postprocessbuildplayer_*'GLOB_NOCASE);
    foreach 
    $file (@files) {
        print 
    "PostProcessBuildPlayer Master: calling " $file "\n";
        
    system($file$ARGV[0], $ARGV[1], $ARGV[2], $ARGV[3], $ARGV[4], $ARGV[5], $ARGV[6]);
    }
    then i put the example iAd4UnityDemo.js on a gameobject and uncomment the line "iAd4Unity.ShowBannerWithPosition(iAd4Unity.BannerPosition.Top);" in the Start function.

    Then i click on build settings and click build -> append

    Then open xCode...but now nothing was added..no Framewor etc.??

    Where is the mistake please?

    thanks
     
  44. jonaphin

    jonaphin

    Joined:
    Dec 31, 2008
    Posts:
    209
    The multi Postprocessbuildplayer setup is already in place.
    Keep the original Postprocessbuildplayer and postprocessbuildplayer_iad files.
    Just create a new one for openfeint called Postprocessbuildplayer_openfeint (respect the filename capitalization as per the package, as I do not have the files under my sight right now)
     
  45. mikolo

    mikolo

    Joined:
    Nov 27, 2009
    Posts:
    249
    sorry it doesnt work.. a step by step Declaration would be great. Nobody wants to destroy the running openfeint stuff. So my first tip...do a copy before.. from the Unity Files and xCode Files.

    I have tryed....but it doesnt work. The files would not patched? So here is the way i tryed form Unity:

    together i have 3 file like this:

    PostprocessBuildPlayer
    code inside:
    PHP:
    #!/usr/bin/perl

    import sys
    import os
    import subprocess
    from pipes import quote

    current_dir 
    os.getcwd() + '/Assets/Editor/'
    sys.argv.pop(0)

    for 
    subdirdirsfiles in os.walk(current_dir):
        for 
    file in files:
            if 
    file.lower().startswith("PostprocessBuildPlayer_"):
                print 
    "Calling: " current_dir "/" file "\n"
                
    cmd current_dir file " " " ".join(quote(arg) for arg in sys.argv)
                
    os.system(cmd)
    PostprocessBuildPlayer_iAd4Unity
    code inside:
    PHP:
    #!/usr/bin/env python
    # Bumped with every new release of the i3d iAd Unity plugin
    i3DiAdUnityVersion 41

    import sys
    import os
    import os
    .path
    import shutil
    import distutils
    .dir_util
    import fnmatch
    from xml
    .dom import minidom
    import subprocess
    import zipfile
    import time

    def main
    ():
        
    open('build.log''w')
        
    f.write('0:' sys.argv[0] + ' 1:' sys.argv[1] + ' 2:' sys.argv[2] + ' 3: ' sys.argv[3] + ' 4:' sys.argv[4] + ' 5:' sys.argv[5] + ' 6:' sys.argv[6])
        
    f.close()
        
        
    publishTarget sys.argv[2]
        print 
    publishTarget
        
        
    if publishTarget == 'iPhone':
            
    xcodeProjectRoot sys.argv[1]
            
            print 
    'Xcode project root: ' xcodeProjectRoot

            workingDir 
    os.getcwd() + '/Assets/Editor/i3diAd'
            
    i3DiAdPackageBundle '/libiad4unity.a'
            
    i3DiAdController '/InGameAdViewController.h'

            
    print 'Starting i3D iAd patch...'
            
            
    # Sanity check
            
    if os.path.exists(workingDir i3DiAdPackageBundle):
                
    # Copy the iAd package bundle
                
    print 'Copying iAd package bundle...'

            
    if os.path.exists(xcodeProjectRoot i3DiAdPackageBundle):
                
    os.remove(xcodeProjectRoot i3DiAdPackageBundle)
            
    shutil.copy(workingDir i3DiAdPackageBundlexcodeProjectRoot "/Libraries" i3DiAdPackageBundle)
            
            if 
    os.path.exists(xcodeProjectRoot i3DiAdController):
                
    os.remove(xcodeProjectRoot i3DiAdController)
            
    shutil.copy(workingDir i3DiAdControllerxcodeProjectRoot "/Classes" i3DiAdController)
            
            
    # Patch the project to include the necessary settings and files
            
    patchDir workingDir
            patch_project
    (patchDirxcodeProjectRoot)
        else:
            print 
    "i3d_iAd4Unity.bundle is missing from your /Assets/Editor/ folder."
            
    print 'Cannot continue i3D iAd patch until the i3d_iAd4Unity.bundle is available.'
            
    cmd """/usr/bin/osascript -e 'tell application "Xcode"' -e 'display dialog "i3D Online notice:\ni3d_iAd4Unity.bundle is missing from /Assets/Editor/." buttons {"Ok"}' -e 'end tell'"""
            
    os.system(cmd)
            
            return

        
    def patch_project(patchDirxcodeProjectRoot):
        print 
    'Patching XCode project file...'
        
    cmd '/usr/bin/osascript patchproject.scpt "%s"' xcodeProjectRoot
        retcode 
    subprocess.call(cmdshell=Truecwd=patchDir)
        if 
    retcode 0:
            print >> 
    sys.stderr"Child was terminated by signal", -retcode
            
    return

        print 
    'Patching AppController.mm'
        
    appControllerPath xcodeProjectRoot '/Classes/AppController.mm'
        
    appControllerFile open(appControllerPath'r')
        
    lines appControllerFile.readlines()
        
    newLines = []
        
    hasInclude False
        needPatching 
    False
        firstLine 
    True
        
    for line in lines:
            if 
    firstLine and not line == '#import "InGameAdViewController.h"\n':
                
    newLines.append('#import "InGameAdViewController.h"\n')
                
    firstLine False
                needPatching 
    True
                
            
    if not needPatching:
                print 
    'Already patched, skipping...'
                
    break
            
            
    newLines.append(line)
            
            if 
    line == """@implementation AppController\n""":
                
    newLines.append("\t@synthesize adViewController;\n")

            if 
    line == """\t[self startUnity:application];\n""":
                
    newLines.append("\tadViewController = [[InGameAdViewController alloc] init];\n")
                
    newLines.append("\tadViewController.appController = self;\n")
                
    newLines.append("\tUIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow];\n")
                
    newLines.append("\t[keyWindow addSubview:adViewController.view];\n")
                
    newLines.append("\t[keyWindow bringSubviewToFront:adViewController.view];\n")
                
    newLines.append("}\n")
                
    newLines.append("\n")
                
    newLines.append("- (void) pauseUnity:(BOOL)status {\n")
                
    newLines.append("\tUnityPause(status);\n")

            if 
    line == """\t_context = nil;\n""":
                
    newLines.append('\t[adViewController release];\n')
                
        
    appControllerFile.close()
        
        if 
    needPatching:
            
    appControllerFile open(appControllerPath'w')
            
    appControllerFile.writelines(newLines)
            
    appControllerFile.flush()
            
    appControllerFile.close()

            print 
    'Patching AppController.h'
            
    appControllerPath xcodeProjectRoot '/Classes/AppController.h'
            
    appControllerFile open(appControllerPath'r')
            
    lines appControllerFile.readlines()
            
    newLines = []

            for 
    line in lines:
                
    newLines.append(line)
                
                if 
    line == """#import <UIKit/UIKit.h>\n""":
                    
    newLines.append("\n")
                    
    newLines.append("@class InGameAdViewController;\n")
            
                if 
    line == """{\n""":
                    
    newLines.append('\tInGameAdViewController *adViewController;\n')
                    
                if 
    line == """}\n""":
                    
    newLines.append('\n')
                    
    newLines.append('@property(nonatomic,retain) InGameAdViewController *adViewController;\n')
                    
    newLines.append('\n')
                    
    newLines.append('- (void) pauseUnity:(BOOL)status;\n')

               
    appControllerFile.close()

        if 
    needPatching:
            
    appControllerFile open(appControllerPath'w')
            
    appControllerFile.writelines(newLines)
            
    appControllerFile.flush()
            
    appControllerFile.close()
            
        print 
    'Completed i3D iAd patch'
        
        
    def decompressZip(filedir):
        
    zf zipfile.ZipFile(file)

        
    # Create directory structure to house files
        
    makeDirs(filezf)

        
    # Extract files to directory structure
        
    for iname in enumerate(zf.namelist()):
            if 
    not name.endswith('/'):
                
    fullPath os.path.join(dirname)
                
    outfile open(fullPath'wb')
                
    outfile.write(zf.read(name))
                
    outfile.flush()
                
    outfile.close()
        

    def makeDirs(filezf):
        
    isdir os.path.isdir
        join 
    os.path.join
        norm 
    os.path.normpath
        split 
    os.path.split
        dirname 
    os.path.dirname

        
    for each in zf.namelist():
            if 
    not each.endswith('/'):
                
    rootname split(each)
                
    absDirRoot dirname(file) + '/'
                
    directory norm(absDirRoot root)
                if 
    not isdir(directory):
                    
    os.makedirs(directory)
       
    def convertStr(s):
        
    """Convert string to int"""
        
    ret 0
        
    try:
            
    ret int(s)
        
    except ValueError:
            print 
    'Invalid version number string in AGON version file: ' s
            
        
    return ret
            
            
    if __name__ == '__main__':
        
    main()
    PostprocessBuildPlayer_OpenFeint
    code inside:

    PHP:
    #!/usr/bin/perl

    # PostprocessBuildPlayer #
    # Post-process build script for OpenFeint integration.

    use File::Basename;
    use 
    Foundation;

    # Paths.
    $installPath $ARGV[0];
    $currDir = `pwd`;
    chomp $currDir;
    $xcodeFiles $currDir."/Assets/Editor/OpenFeint/";

    # Error handling.
    sub handler
    {
        
    my($msg) = @_;
        `
    osascript -e \'tell application \"Finder\" to display dialog \"$msg\" buttons \"OK\"\'`;
        die 
    "$msg\n";
    }
    $SIG{'__DIE__'}  = \&handler;

    # Make sure the OpenFeint directory exists.
    opendir(XCODEPROJECTDIR$xcodeFiles) || die("Cannot find directory $xcodeFiles");
    closedir(XCODEPROJECTDIR);

    # Add all necessary OpenFeint files.
    `osascript \'$currDir/Assets/Editor/OpenFeint/Xcode/UpdateXcodeWithOF.scpt\' \'$installPath\' \'$currDir\'`;
    Can somebody tell me what`s wrong, please?:(

    he do not copy the files in folder Editor/i3DiAd?
     
    Last edited: Nov 15, 2010
  46. mikolo

    mikolo

    Joined:
    Nov 27, 2009
    Posts:
    249
    OK it running now... i don`t know but the file InGameAdViewController.h was copied...but not visible in folder in xCode...and the frameworks libiad4unity.a and iAd.framework was not copied?

    So i added the frameworks on myself and added the file InGameAdViewController.h as existing file.. and it was visible.

    Now i have the problem, that i cant see the banners:

    PHP:
    ShowBanner (Filename: /Users/build/builds/unity-iphone/iphone/Projects/../Runtime/Export/Generated/BaseClass.cpp Line1719)
    Ad is visibleFalse (Filename: /Users/build/builds/unity-iphone/iphone/Projects/../Runtime/Export/Generated/BaseClass.cpp Line1719)
    HideBanner (Filename: /Users/build/builds/unity-iphone/iphone/Projects/../Runtime/Export/Generated/BaseClass.cpp Line1719)
    Ad is visibleFalse (Filename: /Users/build/builds/unity-iphone/iphone/Projects/../Runtime/Export/Generated/BaseClass.cpp Line1719)
    ShowBannerBottom (Filename: /Users/build/builds/unity-iphone/iphone/Projects/../Runtime/Export/Generated/BaseClass.cpp Line1719)
    Ad is visibleFalse (Filename: /Users/build/builds/unity-iphone/iphone/Projects/../Runtime/Export/Generated/BaseClass.cpp Line1719)
    RotateToPortrait (Filename: /Users/build/builds/unity-iphone/iphone/Projects/../Runtime/Export/Generated/BaseClass.cpp Line1719)
    Ad is visibleFalse (Filename: /Users/build/builds/unity-iphone/iphone/Projects/../Runtime/Export/Generated/BaseClass.cpp Line1719)
    RotateToLandscapeRight (Filename: /Users/build/builds/unity-iphone/iphone/Projects/../Runtime/Export/Generated/BaseClass.cpp Line1719)
    Ad is visibleFalse (Filename: /Users/build/builds/unity-iphone/iphone/Projects/../Runtime/Export/Generated/BaseClass.cpp Line1719)
    RotateToPortraitUpsideDown (Filename: /Users/build/builds/unity-iphone/iphone/Projects/../Runtime/Export/Generated/BaseClass.cpp Line1719)
    Ad is visibleFalse (Filename: /Users/build/builds/unity-iphone/iphone/Projects/../Runtime/Export/Generated/BaseClass.cpp Line1719)
    RotateToLandscapeLeft (Filename: /Users/build/builds/unity-iphone/iphone/Projects/../Runtime/Export/Generated/BaseClass.cpp Line1719)
    Ad is visibleFalse (Filename: /Users/build/builds/unity-iphone/iphone/Projects/../Runtime/Export/Generated/BaseClass.cpp Line1719)
    any idea now? please? :)
     
  47. jonaphin

    jonaphin

    Joined:
    Dec 31, 2008
    Posts:
    209
    it's not perl, it looks like Python to me :)


    Regarding OpenFeint, I've never used it, so I can't really help you there.
     
  48. Kripto

    Kripto

    Joined:
    Feb 12, 2007
    Posts:
    119
    I'm trying to purchase your iAd plug in but your site says it's no long for sale? What's the deal?
     
  49. mikolo

    mikolo

    Joined:
    Nov 27, 2009
    Posts:
    249
    jonaphin thank you.

    Maybe there is anybody here who has done and helps? I don`t believe its much work....in Objective-C???
     
  50. mikolo

    mikolo

    Joined:
    Nov 27, 2009
    Posts:
    249
    Condition is getting no error message after installation (buid->append) and patching!
    In my case OF was installed before and was running good.

    If you are working with OF and the iAd Plugin in Unity... a easy solution to run OF and iAd you can do following steps:

    -Uncomment in AppController.mm the header file like this:
    PHP:
    //#import "InGameAdViewController.h"
    -Uncomment in AppController.mm Function applicationDidFinishLaunching:(UIApplication*)application like this:

    PHP:
    printf_console("-> applicationDidFinishLaunching() AppController.mm\n");
    [
    self startUnity:application];
    //adViewController = [[InGameAdViewController alloc] init];
    //adViewController.appController = self;
    //UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow];
    //[keyWindow addSubview:adViewController.view];
    //[keyWindow bringSubviewToFront:adViewController.view];
    -Copy the uncommented 5 lines above

    -Go to AppController+OpenFeint.mm and import the header file like this:
    PHP:
    #import "InGameAdViewController.h"
    -Go to Function didFinishLaunchingWithOptions (in AppController+OpenFeint.mm)

    -Paste the copied lines before and it should run, your code should be look like this:

    PHP:
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        
    printf_console("-> didFinishLaunchingWithOptions() AppController+OpenFeint.mm\n");
        
        [
    self commonInit:application];
            [
    OpenFeint respondToApplicationLaunchOptions:launchOptions]; 
        
        
    /*
         * iAd Integration | paste it here
         */
        
        
    adViewController = [[InGameAdViewController allocinit];
        
    adViewController.appController self;
        
    UIWindow *keyWindow = [[UIApplication sharedApplicationkeyWindow];
        [
    keyWindow addSubview:adViewController.view];
        [
    keyWindow bringSubviewToFront:adViewController.view];
        
        
    /*
         * END iAd Integration
         */
        
        
        
    return YES;
    }

    In my case it works now

    My Software: OF2.6 | Unity iPhone Prof 1.7 | iAd Plugin 1.6.1 | Base SDK 4.1 | Targeting 3.2

    Attention, i think it don`t work on iPad, there come a error, so if you design for both devices you must weak against the framework iAd.framework

    Hope it helps anybody!!!
     
    Last edited: Nov 16, 2010