• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

DelphiXE4iADFramework支持.

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
太赞了这个. 如此也证实了 IOS 的 Framework的使用方式. 定义接口文件,就可以了. 要做的就是语法的转换问题. 
这个方法我也想过,还没有具体实施. 值得参考和扩展,其它的很多Framework 也是可以做到的. 当然还有bug// 离实际可用还有距离,
而我上次提交的App 苹果也给Reject 了. 貌似是分辨率不能支持得很好. - 是我的问题, 我用了一个WebVIew 但加载的页面没有适应ipad.
还有一个问题就是 我的应用太简单了. :) 等有时间再完善一下 再说.
  1     //
  2     // Delphi XE4 - iOS_Library_iAd
  3     //
  4     //  http://blog.naver.com/simonsayz
  5     //  Simon,Choi (최원식옹)
  6     //
  7     //  History
  8     //   2013.05.22 Ver 0.01  1st Release
  9     //
 10     //  Known Bug.
 11     //   - On Simulator, When press ad, Screen will be black.
 12     //     Why ?   Can't solved yet. 2013.05.22
 13     //
 14     //  Warning
 15     //   - This code is not perfect. Just guide to start to how to implement
 16     //
 17     //
 18     unit iOS_Library_iAd;
 19      
 20      
 21     interface
 22      
 23     uses Macapi.ObjectiveC,
 24          iOSapi.CocoaTypes, iOSapi.CoreGraphics, iOSapi.Foundation, iOSapi.UIKit;
 25      
 26     const
 27      libCoreiAd = '/System/Library/Frameworks/iAd.framework/iAd';
 28      
 29     Type
 30      id = Pointer;
 31      
 32      {$M+}
 33     { ADBannerView }
 34       ADBannerViewClass = interface(UIViewClass) end;
 35       ADBannerView      = interface(UIView)
 36         procedure setDelegate (newValue: id); cdecl;
 37         function delegate: id; cdecl;
 38         function isBannerLoaded: Boolean; cdecl;
 39         procedure setRequiredContentSizeIdentifiers (newValue: NSSet); cdecl;
 40         function requiredContentSizeIdentifiers: NSSet; cdecl;
 41         procedure setCurrentContentSizeIdentifier (newValue: NSString); cdecl;
 42         function currentContentSizeIdentifier: NSString; cdecl;
 43         {class} function sizeFromBannerContentSizeIdentifier
 44                          (contentSizeIdentifier: NSString): CGSize; cdecl;
 45         procedure setAdvertisingSection (newValue: NSString); cdecl;
 46         function advertisingSection: NSString; cdecl;
 47         function isBannerViewActionInProgress: Boolean; cdecl;
 48         procedure cancelBannerViewAction; cdecl;
 49       end;
 50      TADBannerView = class (TOCGenericImport<ADBannerViewClass,ADBannerView>) end;
 51      
 52      
 53     { ADBannerViewDelegate Protocol }
 54       ADBannerViewDelegate = interface(IObjectiveC)
 55         procedure bannerViewWillLoadAd(banner: ADBannerView); cdecl;
 56         procedure bannerViewDidLoadAd(banner: ADBannerView); cdecl;
 57         procedure bannerView(banner: ADBannerView; didFailToReceiveAdWithError: NSError); cdecl;
 58         function  bannerViewActionShouldBegin
 59                   (banner: ADBannerView; willLeaveApplication : Boolean): Boolean; cdecl;
 60         procedure bannerViewActionDidFinish(banner: ADBannerView); cdecl;
 61       end;
 62      
 63       //---------------------------------------------------------------------------
 64       TNotifyEvent        = Procedure (Sender : TObject) of Object;
 65       TNotifyMessageEvent = Procedure (Sender : TObject; Msg : String) of Object;
 66      
 67       //
 68       TADBannerViewDelegate = class(TOCLocal,ADBannerViewDelegate)
 69       Private
 70        FMe     : TObject;
 71        FOnLoad : TNotifyEvent;
 72        FOnFail : TNotifyEvent;
 73        FOnMsg  : TNotifyMessageEvent;
 74       public
 75        procedure bannerViewWillLoadAd(banner: ADBannerView); cdecl;
 76        procedure bannerViewDidLoadAd(banner: ADBannerView); cdecl;
 77        procedure bannerView(banner: ADBannerView; didFailToReceiveAdWithError: NSError); cdecl;
 78        function  bannerViewActionShouldBegin
 79                  (banner: ADBannerView; willLeaveApplication : Boolean): Boolean; cdecl;
 80        procedure bannerViewActionDidFinish(banner: ADBannerView); cdecl;
 81       end;
 82      
 83      //
 84      TiOSiAd = Class(TObject)
 85      Private
 86       //
 87       Function  GetOnLoad          : TNotifyEvent;
 88       Procedure SetOnLoad  ( Value : TNotifyEvent);
 89       Function  GetOnFail          : TNotifyEvent;
 90       Procedure SetOnFail  ( Value : TNotifyEvent);
 91       Function  GetOnMsg           : TNotifyMessageEvent;
 92       Procedure SetOnMsg   ( Value : TNotifyMessageEvent);
 93      Public
 94       FSelf    : TObject;
 95       FControl :  ADBannerView;
 96       FEvent   : TADBannerViewDelegate;
 97       //
 98       Constructor Create; Virtual;
 99       Destructor  Destroy; Override;
100       Procedure   Free;
101       //
102       Property  OnLoad : TNotifyEvent        Read GetOnLoad Write SetOnLoad;
103       Property  OnFail : TNotifyEvent        Read GetOnFail Write SetOnFail;
104       Property  OnMsg  : TNotifyMessageEvent REad GetOnMsg  Write SetOnMsg;
105      End;
106      
107     // exported string consts
108      
109     function ADErrorDomain: NSString;
110     function ADBannerContentSizeIdentifier320x50: NSString; // deprecated 'in iOS 4.2 and later';
111     function ADBannerContentSizeIdentifier480x32: NSString; // deprecated 'in iOS 4.2 and later';
112     function ADBannerContentSizeIdentifierPortrait: NSString;
113     function ADBannerContentSizeIdentifierLandscape: NSString;
114      
115     implementation
116      
117     uses
118       Posix.Dlfcn;
119     var
120       iAdModule: THandle;
121      
122     const
123       iAdFwk: string = '/System/Library/Frameworks/iAd.framework/iAd';
124      
125     function ADErrorDomain: NSString;
126      begin
127       Result := CocoaNSStringConst(iAdFwk, 'ADErrorDomain');
128      end;
129      
130     function ADBannerContentSizeIdentifier320x50: NSString;
131      begin
132       Result := CocoaNSStringConst(iAdFwk, 'ADBannerContentSizeIdentifier320x50');
133      end;
134      
135     function ADBannerContentSizeIdentifier480x32: NSString;
136      begin
137       Result := CocoaNSStringConst(iAdFwk, 'ADBannerContentSizeIdentifier480x32');
138      end;
139      
140     function ADBannerContentSizeIdentifierPortrait: NSString;
141      begin
142       Result := CocoaNSStringConst(iAdFwk, 'ADBannerContentSizeIdentifierPortrait');
143      end;
144      
145     function ADBannerContentSizeIdentifierLandscape: NSString;
146      begin
147       Result := CocoaNSStringConst(iAdFwk, 'ADBannerContentSizeIdentifierLandscape');
148      end;
149      
150     //------------------------------------------------------------------------------
151     //
152     //  iOSAd  := TiOSiAd.Create(nil);
153     //  iOSAd.Parent  := Self.View;
154     //
155     //------------------------------------------------------------------------------
156      
157     //
158     Procedure TADBannerViewDelegate.bannerViewWillLoadAd(banner: ADBannerView);
159      begin
160       if Assigned(FOnLoad) then FOnLoad(FMe);
161       if Assigned(FOnMsg ) then FOnMsg(FMe,'willLoadAd');
162      end;
163      
164     //
165     Procedure TADBannerViewDelegate.bannerView
166               (banner: ADBannerView; didFailToReceiveAdWithError: NSError);
167      begin
168       if Assigned(FOnFail) then FOnFail(FMe);
169       if Assigned(FOnMsg ) then FOnMsg(FMe,'didFailToReceiveAdWithError');
170      end;
171      
172     //
173     procedure TADBannerViewDelegate.bannerViewDidLoadAd(banner: ADBannerView); cdecl;
174      begin
175       if Assigned(FOnFail) then FOnFail(FMe);
176       if Assigned(FOnMsg ) then FOnMsg(FMe,'ViewDidLoadAd');
177      end;
178      
179     //
180     function  TADBannerViewDelegate.bannerViewActionShouldBegin
181     (banner: ADBannerView; willLeaveApplication : Boolean): Boolean; cdecl;
182      begin
183       if Assigned(FOnFail) then FOnFail(FMe);
184       if Assigned(FOnMsg ) then FOnMsg(FMe,'ActionShouldBegin');
185       Result := True;
186      end;
187      
188     //
189     procedure TADBannerViewDelegate.bannerViewActionDidFinish(banner: ADBannerView); cdecl;
190      begin
191       if Assigned(FOnFail) then FOnFail(FMe);
192       if Assigned(FOnMsg ) then FOnMsg(FMe,'ActionDidFinish');
193      end;
194      
195     //------------------------------------------------------------------------------
196      
197     //
198     Constructor TiOSiAd.Create;
199      begin
200       inherited;
201       // initialize --------------------------
202       FEvent         := TADBannerViewDelegate.Create;
203       FEvent.FOnLoad := nil;
204       FEvent.FOnFail := nil;
205       //
206       FControl :=  TADBannerView.Wrap( TADBannerView.OCClass.alloc);
207       FControl.initWithFrame( CGRectMake (0,480-20-50,320,50) );
208       FControl.setCurrentContentSizeIdentifier(ADBannerContentSizeIdentifierPortrait);
209       FControl.setDelegate(FEvent.GetObjectID);
210       //
211       FSelf := Self;
212      end;
213      
214     Destructor TiOSiAd.Destroy;
215      begin
216       //
217       FControl.release;
218       FControl := nil;
219       //
220       FEvent.Free;
221       FEvent   := nil;
222       //
223       inherited;
224      end;
225      
226     //
227     Procedure  TiOSiAd.Free;
228      begin
229             If Self <> nil then
230              Destroy;
231      end;
232      
233     //
234     Function  TiOSiAd.GetOnLoad : TNotifyEvent;
235      begin
236       Result := FEvent.FOnLoad;
237      end;
238      
239     //
240     Procedure TiOSiAd.SetOnLoad ( Value : TNotifyEvent );
241      begin
242       FEvent.FOnLoad := Value;
243      end;
244      
245     //
246     Function  TiOSiAd.GetOnFail : TNotifyEvent;
247      begin
248       Result := FEvent.FOnFail;
249      end;
250      
251     //
252     Procedure TiOSiAd.SetOnFail ( Value : TNotifyEvent );
253      begin
254       FEvent.FOnFail := Value;
255      end;
256      
257     //
258     Function  TiOSiAd.GetOnMsg : TNotifyMessageEvent;
259      begin
260       Result := FEvent.FOnMsg;
261      end;
262      
263     //
264     Procedure TiOSiAd.SetOnMsg ( Value : TNotifyMessageEvent );
265      begin
266       FEvent.FOnMsg := Value;
267      end;
268      
269     initialization
270       iAdModule := dlopen(MarshaledAString(libCoreiAd), RTLD_LAZY);
271      
272     finalization
273       dlclose(iAdModule);
274      
275     end.

只需要把上述两个文件保存以后 加入工程就可以了. 

 

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap