AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Umsetzung von XCode nach Delphi

Ein Thema von RWarnecke · begonnen am 22. Sep 2013 · letzter Beitrag vom 6. Jan 2014
 
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, 21: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
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 18:01 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz