IOS上监听用户抓屏的事件
Submitted by hubdog on Sat, 2020-12-26 22:16
unit CMain; interface uses System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, Macapi.ObjectiveC, iOSapi.Foundation, System.TypInfo,iOSapi.UIKit, FMX.Controls.Presentation, FMX.StdCtrls; type TShotListener=class; TFormMain = class(TForm) lblMsg: TLabel; procedure FormCreate(Sender: TObject); procedure FormDestroy(Sender: TObject); private { Private declarations } FListener:TShotListener; public { Public declarations } end; IScreenShoted = interface(NSObject) ['{72E80282-B503-4012-96A2-85540EF061C9}'] procedure OnShot; cdecl; end; TShotListener=class(TOCLocal) protected { TOCLocal } function GetObjectiveCClass: PTypeInfo; override; public procedure OnShot();cdecl; end; var FormMain: TFormMain; implementation uses Macapi.Helpers, Macapi.ObjCRuntime; {$R *.fmx} procedure TFormMain.FormCreate(Sender: TObject); begin // FListener:=TShotListener.Create; TNSNotificationCenter.Wrap(TNSNotificationCenter.OCClass.defaultCenter).addObserver(FListener.GetObjectID, sel_getUid('OnShot'), StringToID(NSStrToStr(UIApplicationUserDidTakeScreenshotNotification)), nil); end; { TShotListener } function TShotListener.GetObjectiveCClass: PTypeInfo; begin Result := TypeInfo(IScreenShoted); end; procedure TShotListener.OnShot; begin // FormMain.lblMsg.Text:='Screen Shotted'; end; procedure TFormMain.FormDestroy(Sender: TObject); begin TNSNotificationCenter.Wrap(TNSNotificationCenter.OCClass.defaultCenter).removeObserver(FListener.GetObjectID); FListener.Free; end; end.
Attachment | Size |
---|---|
ScreenShotListener.zip | 10.72 KB |