Einzelnen Beitrag anzeigen

daywalker9

Registriert seit: 1. Jan 2010
Ort: Leer
594 Beiträge
 
Delphi XE3 Professional
 
#5

AW: Umsetzung von XCode nach Delphi

  Alt 24. Sep 2013, 22:07
Schau mal hier

Delphi-Quellcode:
unit Unit5;

interface

uses
  System.TypInfo,
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, iOSapi.UIKit,
  iOSapi.Foundation, Macapi.ObjCRuntime, Macapi.ObjectiveC, System.Mac.CFUtils,
  Macapi.OCMarshal, iOSapi.CocoaTypes, Macapi.CoreFoundation, FMX.StdCtrls;

type
  INotifier = interface(NSObject)
    ['{B0069354-3EF8-48F4-84E1-E6223E648BFA}']
    procedure CallBack(notification : Pointer); cdecl;
  end;

  TNotifier = class(TOCLOcal)
  protected
    function GetObjectiveCClass: PTypeInfo; override;
  public
    procedure CallBack(notification: Pointer); cdecl;
  end;

  TForm5 = class(TForm)
    Button1: TButton;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    FNotifier: TNOtifier;
  public
    { Public declarations }
  end;

var
  Form5: TForm5;

implementation

{$R *.fmx}

function UIDeviceBatteryLevelDidChangeNotification : CFStringRef;
begin
  Result := CFStringRef(CocoaPointerConst(libUIKit, 'UIDeviceBatteryLevelDidChangeNotification')^);
end;

function UIDeviceBatteryStateDidChangeNotification : CFStringRef;
begin
  Result := CFStringRef(CocoaPointerConst(libUIKit, 'UIDeviceBatteryStateDidChangeNotification')^);
end;

procedure TForm5.Button1Click(Sender: TObject);
var
  lNSSotificationCenter: NSNotificationCenter;
  lCFString: TCFString;
  s:String;
begin
  FNotifier := TNotifier.Create;

  lCFString := UIDeviceBatteryLevelDidChangeNotification;

  lNSSotificationCenter := TNSNotificationCenter.Wrap(TNSNotificationCenter.OCClass.defaultCenter);
  lNSSotificationCenter.addObserver(FNotifier.GetObjectID,
    sel_getUid('CallBack:'),
    (NSSTR(lCFString.AsString()) as ILocalObject).GetObjectID, nil);

  lCFString := UIDeviceBatteryStateDidChangeNotification;

  lNSSotificationCenter.addObserver(FNotifier.GetObjectID,
    sel_getUid('CallBack:'),
    (NSSTR(lCFString.AsString()) as ILocalObject).GetObjectID, nil);

  TUIDevice.Wrap( TUIDevice.OCClass.currentDevice).setBatteryMonitoringEnabled(true);
end;


{ TNotifier }

procedure TNotifier.CallBack(notification: Pointer);
begin
  showmessage('Notification');
end;

function TNotifier.GetObjectiveCClass: PTypeInfo;
begin
  result:=TypeInfo(INotifier);
end;
Lars
  Mit Zitat antworten Zitat