我正在尝试使用Delphi / Firemonkey重现UNUserNotificationCenter(iOS10) . 该应用程序成功授权接收通知并按预期显示所有本地通知,现在UNUserNotificationCenter不会触发委托事件(例如,当用户点击通知项目时) .

type
  UNUserNotificationCenterDelegate = interface(IObjectiveC)
    ['{817A2C54-2F1E-4322-8BDB-2E77F8FAB1AE}']
    procedure willPresentNotification(center: UNUserNotificationCenter; notification: UNNotification; completionHandler: TUserNotificationsWithCompletionHandler1); cdecl;
    procedure didReceiveNotificationResponse(center: UNUserNotificationCenter; response: UNNotificationResponse; completionHandler: TUserNotificationsWithCompletionHandler2); cdecl;
  end;

我的委托对象:

type
  TUserNotificationCenterDelegate = class(TOCLocal, UNUserNotificationCenterDelegate)
  public
    procedure willPresentNotification(center: UNUserNotificationCenter; notification: UNNotification; completionHandler: TUserNotificationsWithCompletionHandler1); cdecl;
    procedure didReceiveNotificationResponse(center: UNUserNotificationCenter; response: UNNotificationResponse; completionHandler: TUserNotificationsWithCompletionHandler2); cdecl;
  end;

var
  NotificationCenterDelegate: TUserNotificationCenterDelegate; 

implementation

[...]

function TfrmApplication.AppEventHandler(AAppEvent: TApplicationEvent; AContext: TObject): Boolean;
begin
  Result := true;

  case AAppEvent of
    TApplicationEvent.FinishedLaunching:
    begin
       UserNotificationCenterDelegate := TUserNotificationCenterDelegate.Create;
       TUNUserNotificationCenter.OCClass.currentNotificationCenter.setDelegate((UserNotificationCenterDelegate as ILocalObject).GetObjectID);   
       TUNUserNotificationCenter.OCClass.currentNotificationCenter.requestAuthorizationWithOptions(UNAuthorizationOptionAlert + UNAuthorizationOptionSound, nil);
    end;
    TApplicationEvent.EnteredBackground:
    begin
      DEF_APPLICATION_IN_BACKGROUND := true;
    end;
    TApplicationEvent.BecameActive:
    begin
      DEF_APPLICATION_IN_BACKGROUND := false;
      TUNUserNotificationCenter.OCClass.currentNotificationCenter.removeAllDeliveredNotifications;
    end;
  else
    Result := false;
  end;
end;

每次应用通知时,应用程序处于前台或用户点击通知时,应每次都提出以下事件 . 但没有任何反应 .

procedure TUserNotificationCenterDelegate.willPresentNotification(center: UNUserNotificationCenter; notification: UNNotification; completionHandler: TUserNotificationsWithCompletionHandler1); cdecl;
var
  aImp: procedure(options: NSUInteger); cdecl;
  aOptions: UNNotificationPresentationOptions;
begin
  WriteLog(AP_LOG_HEADER + 'Will present notification');
  //completionHandler
  @aImp := imp_implementationWithBlock(completionHandler);
  aOptions := UNNotificationPresentationOptionAlert;
  aImp(aOptions);
  imp_removeBlock(@aImp);
end;

procedure TUserNotificationCenterDelegate.didReceiveNotificationResponse(center: UNUserNotificationCenter; response: UNNotificationResponse; completionHandler: TUserNotificationsWithCompletionHandler2); cdecl;
var
  aImp: procedure(); cdecl;
begin
  WriteLog(AP_LOG_HEADER + 'Receive notification response');
  //completionHandler
  @aImp := imp_implementationWithBlock(completionHandler);
  aImp();
  imp_removeBlock(@aImp);
end;

我究竟做错了什么?谢谢!