0

How i can override the delegate methods, for example viewDidLoad, for native UIViewController with Delphi/FMX?

Thanks!

0

1 Answer 1

1

exemple with bannerViewWillLoadAd (principle is the same for viewDidLoad with UIViewController) :

  ADBannerViewDelegate = interface(IObjectiveC)
    ['{95249262-9E7D-4841-B8E4-9EBBDADF3485}']
    procedure bannerView(banner: ADBannerView; didFailToReceiveAdWithError: NSError); cdecl;
    procedure bannerViewActionDidFinish(banner: ADBannerView); cdecl;
    function bannerViewActionShouldBegin(banner: ADBannerView; willLeaveApplication: Boolean): Boolean; cdecl;
    procedure bannerViewDidLoadAd(banner: ADBannerView); cdecl;
    procedure bannerViewWillLoadAd(banner: ADBannerView); cdecl;
  end;

  TiOSBannerAdDelegate = class(TOCLocal, ADBannerViewDelegate)
  private
    [weak]FAd : TiOSBannerAd;
  public
    procedure SetAd(Ad: TiOSBannerAd);
    procedure bannerView(banner: ADBannerView; didFailToReceiveAdWithError: NSError); cdecl;
    procedure bannerViewActionDidFinish(banner: ADBannerView); cdecl;
    function bannerViewActionShouldBegin(banner: ADBannerView; willLeaveApplication: Boolean): Boolean; cdecl;
    procedure bannerViewDidLoadAd(banner: ADBannerView); cdecl;
    procedure bannerViewWillLoadAd(banner: ADBannerView); cdecl;
  end;

procedure TiOSBannerAdDelegate.bannerViewDidLoadAd(banner: ADBannerView);
begin
  if (FAd <> nil) and (FAd.FAdControl <> nil) then
    FAd.FAdControl.DoDidLoad;
end;

  TiOSBannerAd = class(TInterfacedObject, IBannerAd)
  private
    FAd: ADBannerView;
    FAdControl: TCustomBannerAd;
    FDelegate: TiOSBannerAdDelegate;
    FOrientationChangedId: Integer;
    procedure OrientationChangedHandler(const Sender: TObject; const Msg: TMessage);
  public
    constructor Create;
    destructor Free;
    { ICommonAd }
    procedure CancelAction;
    function IsActionInProgress: Boolean;
    function IsLoaded: Boolean;
    function GetAdUnitID: string;
    procedure SetAdUnitID(const Value: string);
    procedure LoadAd;
    { IBannerAd }
    procedure SetBannerAdControl(const AValue: TCustomBannerAd);
    function GetParent: TFmxObject;
    function GetVisible: Boolean;
    procedure Show;
    procedure Hide;
    procedure UpdateControlMetrics;
    procedure UpdateContentFromControl;
  end;

procedure TiOSBannerAd.SetBannerAdControl(const AValue: TCustomBannerAd);
var
  SizesArray: NSMutableArray;
  SizesSet: NSSet;
begin
  FAdControl := AValue;
  if FAdControl <> nil then
  begin
    FAd := TADBannerView.Create;
    FDelegate := TiOSBannerAdDelegate.Create;
    FDelegate.SetAd(Self);
    FAd.setDelegate(FDelegate.GetObjectID);
    SizesArray := TNSMutableArray.Create;
    SizesArray.addObject((ADBannerContentSizeIdentifierLandscape as ILocalObject).GetObjectID);
    SizesArray.addObject((ADBannerContentSizeIdentifierPortrait as ILocalObject).GetObjectID);
    SizesSet := TNSSet.Wrap(TNSSet.OCClass.setWithArray(SizesArray));
    SizesArray.release;
    FAd.setRequiredContentSizeIdentifiers(SizesSet);

    UpdateControlMetrics
  end
  else
  begin
    FAd.setDelegate(nil);
    FAd.release;
    FAd := nil;
    FDelegate := nil;
  end;
end;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.