如何在Delphi XE2中访问iOS加速度计?

发布于 2024-12-02 23:15:38 字数 64 浏览 1 评论 0 原文

如何使用 Delphi XE2 访问 iOS 中的加速度计?

我尝试查看 IDE,但没有找到组件。

How do I access the accelerometer in iOS using Delphi XE2?

I tried looking through the IDE but did not find a component.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

各自安好 2024-12-09 23:15:38

Delphi XE2 支持在 Mac 上部署到 OSX。部署到 iPhone 显然非常简单,但它仍然涉及使用 XCode 作为最终部署工具。由于 Delphi 并不“正式”支持部署到 iPhone 硬件,因此我怀疑它们是否包含任何特定于它的组件。

免责声明:我几个小时前刚刚下载了 XE2,到目前为止我只部署了一个 mac 应用程序(而且它运行得很好)。所以我距离专家还很远。

编辑:Anders Ohlsson 显然已经为 XE2 编写了一个加速计组件。我还没有尝试过,但是就在这里

Delphi XE2 supports deploying to OSX on a mac. Deploying to an iPhone is apparently pretty easy, but it still involves using XCode as a final deployment tool. Since Delphi doesn't "officially" support deploying to iPhone hardware, I doubt they have included any components that are specific to it.

Disclaimer: I just downloaded XE2 a few hours ago, and I've only deployed one mac application so far (and it worked beautifully). So I'm far from an expert.

Edit: Anders Ohlsson has apparently written an accelerometer component for XE2. I have not tried it, but here it is.

微凉 2024-12-09 23:15:38

约瑟夫是对的。 Philip Hess 一直在为 Delphi iOS 新闻组和其他有用信息做出贡献,例如:

https://forums.embarcadero.com/message.jspa?messageID=390713&tstart=125

他也有这个页面,在这里:

http://web.me.com/macpgmr/ObjP/Xcode4/ObjP_Intro.html

这可能对您有帮助。我目前正在费力地完成这一切,以便使用 CoreLocation 服务(以及其他服务)。这绝对不适合胆小的人。

Joseph is correct. Philip Hess has been contributing to the Delphi iOS newsgroups, and other useful information, eg:

https://forums.embarcadero.com/message.jspa?messageID=390713&tstart=125

He also has this page, here:

http://web.me.com/macpgmr/ObjP/Xcode4/ObjP_Intro.html

Which may be helpful to you. I'm currently wading through it all in order to use the CoreLocation services (amongst others). It's definitely not for the faint of heart.

欢你一世 2024-12-09 23:15:38

Embarcadero 博客上有一个读取加速度计的组件:
http://edn.embarcadero.com/article/41748
以下是该组件的下载链接:http://cc.embarcadero.com/item/28609

这是 Anders Ohlsson 的源代码:
(我用它来构建 GPS/指南针的组件)。

unit Accelerometer;

{$IFDEF FPC}
{$mode objfpc}{$H+}
{$modeswitch objectivec1}
{$ENDIF}

interface

uses
  SysUtils, Classes, FMX_Types
{$IFDEF FPC}
  , iPhoneAll
{$ENDIF}
  ;

type
  TAccelerateEvent = procedure(x,y : Double) of object;

  TiOSAccelerometer = class(TFmxObject)
  private
    FOnAccelerate: TAccelerateEvent;
    { Private declarations }
  protected
    { Protected declarations }
  public
    { Public declarations }
    constructor Create(AOwner: TComponent); override;
  published
    { Published declarations }
    property OnAccelerate: TAccelerateEvent read FOnAccelerate write FOnAccelerate;
  end;

{$IFDEF FPC}
const
  kAccelerometerFrequency = 100.0; // Hz
{$ENDIF}

{$IFDEF FPC}
type
  UIAcceleration = objcclass external (NSObject)
  public
    function timestamp: NSTimeInterval; message 'timestamp';
    function x: UIAccelerationValue; message 'x';
    function y: UIAccelerationValue; message 'y';
    function z: UIAccelerationValue; message 'z';
  end;
{$ENDIF}

{$IFDEF FPC}
type
  AccDelegate = objcclass(NSObject)
    procedure accelerometer_didAccelerate(accelerometer: UIAccelerometer; acceleration: UIAcceleration); message 'accelerometer:didAccelerate:';
  end;
{$ENDIF}

{$IFDEF FPC}
var
  AccDelegatVar: AccDelegate;
{$ENDIF}

var
  MyAccelerometer: TiOSAccelerometer;

procedure Register;

implementation

{$IFDEF FPC}
procedure AccDelegate.accelerometer_didAccelerate(accelerometer: UIAccelerometer; acceleration: UIAcceleration);
begin
  if Assigned(MyAccelerometer) then
    if Assigned(MyAccelerometer.FOnAccelerate) then
      MyAccelerometer.FOnAccelerate(acceleration.x,acceleration.y);
end;
{$ENDIF}

constructor TiOSAccelerometer.Create(AOwner: TComponent);
begin
  inherited;
  {$IFDEF FPC}
  UIAccelerometer.sharedAccelerometer.setUpdateInterval(1.0 / kAccelerometerFrequency);
  AccDelegatVar := AccDelegate.alloc;
  UIAccelerometer.sharedAccelerometer.setDelegate(AccDelegatVar);
  {$ENDIF}
end;

procedure Register;
begin
  RegisterComponents('iOS', [TiOSAccelerometer]);
end;

end.

There's a component that reads the accelerometer on the Embarcadero blog:
http://edn.embarcadero.com/article/41748
Here's the download link for the component: http://cc.embarcadero.com/item/28609

And here's the source code by Anders Ohlsson:
(I used this to build a component for the GPS/Compass).

unit Accelerometer;

{$IFDEF FPC}
{$mode objfpc}{$H+}
{$modeswitch objectivec1}
{$ENDIF}

interface

uses
  SysUtils, Classes, FMX_Types
{$IFDEF FPC}
  , iPhoneAll
{$ENDIF}
  ;

type
  TAccelerateEvent = procedure(x,y : Double) of object;

  TiOSAccelerometer = class(TFmxObject)
  private
    FOnAccelerate: TAccelerateEvent;
    { Private declarations }
  protected
    { Protected declarations }
  public
    { Public declarations }
    constructor Create(AOwner: TComponent); override;
  published
    { Published declarations }
    property OnAccelerate: TAccelerateEvent read FOnAccelerate write FOnAccelerate;
  end;

{$IFDEF FPC}
const
  kAccelerometerFrequency = 100.0; // Hz
{$ENDIF}

{$IFDEF FPC}
type
  UIAcceleration = objcclass external (NSObject)
  public
    function timestamp: NSTimeInterval; message 'timestamp';
    function x: UIAccelerationValue; message 'x';
    function y: UIAccelerationValue; message 'y';
    function z: UIAccelerationValue; message 'z';
  end;
{$ENDIF}

{$IFDEF FPC}
type
  AccDelegate = objcclass(NSObject)
    procedure accelerometer_didAccelerate(accelerometer: UIAccelerometer; acceleration: UIAcceleration); message 'accelerometer:didAccelerate:';
  end;
{$ENDIF}

{$IFDEF FPC}
var
  AccDelegatVar: AccDelegate;
{$ENDIF}

var
  MyAccelerometer: TiOSAccelerometer;

procedure Register;

implementation

{$IFDEF FPC}
procedure AccDelegate.accelerometer_didAccelerate(accelerometer: UIAccelerometer; acceleration: UIAcceleration);
begin
  if Assigned(MyAccelerometer) then
    if Assigned(MyAccelerometer.FOnAccelerate) then
      MyAccelerometer.FOnAccelerate(acceleration.x,acceleration.y);
end;
{$ENDIF}

constructor TiOSAccelerometer.Create(AOwner: TComponent);
begin
  inherited;
  {$IFDEF FPC}
  UIAccelerometer.sharedAccelerometer.setUpdateInterval(1.0 / kAccelerometerFrequency);
  AccDelegatVar := AccDelegate.alloc;
  UIAccelerometer.sharedAccelerometer.setDelegate(AccDelegatVar);
  {$ENDIF}
end;

procedure Register;
begin
  RegisterComponents('iOS', [TiOSAccelerometer]);
end;

end.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文