Hello all

Hello all,
I want to detect IOS device type,
I want to know device is Iphone or Ipad how i can get this info?

Comments

  1. Hi, You can use FMX.Helpers.iOS IsPhone and IsPad function or use nextcode:

      Result := TUIDevice.Wrap(TUIDevice.OCClass.currentDevice).userInterfaceIdiom = UIUserInterfaceIdiomPad;

    ReplyDelete
  2. But IsPhone check that current device - is iPhone. But IsPad check that current interface idiom is Pad. On iPad we can has two idiom together. For example, for application which is runned on iPad as iPhone application will have iPhone idiom of interface

    ReplyDelete
  3. Is that hypothesis, or have you verified this as fact?

    ReplyDelete
  4. Ярослав Бровин  I'm aware of both those UIDevice members. I was questioning whether the issue of both idioms being available on 1 device was proven/documented, and neither link appears to make any mention of this. So my question stands.

    ReplyDelete
  5. Brian Long I don't know about existence documentation about it. Because this feature is only for iOS devices

    ReplyDelete
  6. Something like this, then?


    class function DeviceHardware.IsIPad: Boolean;
    var
      currentDevice: UIDevice;
    begin
      currentDevice := TUIDevice.Wrap(TUIDevice.OCClass.currentDevice);
      Result := currentDevice.model.rangeOfString(NSSTR('iPad')).location <> NSNotFound
    end;

    class function DeviceHardware.IsIPhone: Boolean;
    var
      currentDevice: UIDevice;
    begin
      currentDevice := TUIDevice.Wrap(TUIDevice.OCClass.currentDevice);
      Result := currentDevice.model.rangeOfString(NSSTR('iPhone')).location <> NSNotFound
    end;

    class function DeviceHardware.IsIPod: Boolean;
    var
      currentDevice: UIDevice;
    begin
      currentDevice := TUIDevice.Wrap(TUIDevice.OCClass.currentDevice);
      Result := currentDevice.model.rangeOfString(NSSTR('iPod')).location <> NSNotFound
    end;

    ReplyDelete
  7. Oh, I just looked at the FMX.Helpers.iOS iSPhone function and it does the same as the phone test I just posted. I don't have an iPad to test whether the pad one works or not. I was possibly getting confused with the content of hardware property that iOS devs normally use to do this job.
    If someone can tell me if the iPad/iPod versions work or not, then if not I'll post a fuller unit that has working (but less general) code.

    ReplyDelete
  8. Hi Brian,
    it is working - just checked on iPad mini in my lunch break :-)
    Can you tell me where I can find more information on the wrap method?

    ReplyDelete
  9. The source :o)

    Wrap takes an Objective-C object pointer and wraps it into a suitable Delphi object, if appropriate

    ReplyDelete
  10. Thanks for the answer - and in the JNI area it would take a Java object pointer I guess.

    ReplyDelete
  11. try this:

    var
      _xDevice: IFMXDeviceService;
    begin
      _xDevice := TplatformServices.Current.GetPlatformService(IFMXDeviceService) as IFMXDeviceService;

      if Pos('iPad', _xDevice.GetModel) > 0 then
      begin
        //Bla Bla
      end;

    ReplyDelete
  12. Ivane Katsitadze
    Undeclared IFMXDeviceService
    which file i need to use for declaration?

    ReplyDelete
  13. Qhy not use the FMX.Helpers.iOS isPad and isPhone-functions?

    ReplyDelete
  14. Roland Kossow
    It's not work in my case i don't know why

    ReplyDelete
  15. If it should not work wih the built-in functions you should QC the issue.
    The interface Ivane referred to can be found in FMX.Platform .

    ReplyDelete
  16. Roland Kossow
    I can't open your project

    ReplyDelete
  17. Roland Kossow
    Ivane Katsitadze 
    It's work correct, thanks.

    ReplyDelete

Post a Comment