Page 1 of 1

The native push

PostPosted: Sat Mar 18, 2017 7:50 am
by Lena
Hi.
I found information how to send native push without Kinvey (but in Russian from http://fire-monkey.ru):
Part1
Part2
In the Part2, all the code on Delphi and no one in the Russian forum can translate it into C++. :(
Please help translate the code into C++.

Re: The native push

PostPosted: Mon Mar 20, 2017 8:06 am
by Lena
How it will be on С++?

Code: Select all
if (TPushService.TChange.DeviceToken in AChange) and
    Assigned(FPushServiceConnection)


//***
 procedure OnReceiveNotificationEvent(Sender: TObject;
    const ANotification: TPushServiceNotification);
  procedure OnServiceConnectionChange(Sender: TObject;
    AChange: TPushService.TChanges);

Re: The native push

PostPosted: Mon Mar 20, 2017 1:59 pm
by rlebeau
Lena wrote:How it will be on С++?


Try something like this:

Code: Select all
#include <System.PushNotification.hpp>
#if defined(__ANDROID__)
#include <FMX.PushNotification.Android.hpp>
#endif
#if defined(__APPLE__) && (defined(__arm__) || defined(__arm64__))
#include <FMX.PushNotification.IOS.hpp>
#endif

...

const String FAndroidServerKey = L"63538920422";

...

private:
    // Private declarations
    String FDeviceID;
    String FDeviceToken;
 
    TPushService *FPushService;
    TPushServiceConnection *FPushServiceConnection;
 
    void __fastcall OnReceiveNotificationEvent(TObject *Sender, TPushServiceNotification* const ANotification);
    void __fastcall OnServiceConnectionChange(TObject *Sender, TPushService::TChanges AChange);
 
    void __fastcall PushServiceRegister();

...

void __fastcall TFormMain::OnReceiveNotificationEvent(TObject *Sender, TPushServiceNotification* const ANotification)
{
    ShowMessage(ANotification->Json->ToString());
}
 
void __fastcall TFormMain::OnServiceConnectionChange(TObject *Sender, TPushService::TChanges AChange)
{
    if (AChange.Contains(TPushService::TChange::DeviceToken) && (FPushServiceConnection))
    {
        FDeviceID = FPushService->DeviceIDValue[TPushService_TDeviceIDNames_DeviceID];
        FDeviceToken = FPushService->DeviceTokenValue[TPushService_TDeviceTokenNames_DeviceToken];
    }
}

void __fastcall TFormMain::PushServiceRegister()
{
    FPushService = nullptr;
    FPushServiceConnection = nullptr;
 
    #if defined(__ANDROID__)
    FPushService = TPushServiceManager::Instance->GetServiceByName(TPushService_TServiceNames_GCM);
    FPushService->AppProps[TPushService_TAppPropNames_GCMAppID] = FAndroidServerKey;
    #endif
    #if defined(__APPLE__) && (defined(__arm__) || defined(__arm64__))
    FPushService = TPushServiceManager::Instance->GetServiceByName(TPushService_TServiceNames_APS);
    #endif
    if (FPushService)
    {
        FPushServiceConnection = new TPushServiceConnection(FPushService);
        FPushServiceConnection->OnChange = &OnServiceConnectionChange;
        FPushServiceConnection->OnReceiveNotification = &OnReceiveNotificationEvent;
        FPushServiceConnection->Active = true;
 
        FDeviceID = FPushService->DeviceIDValue[TPushService_TDeviceIDNames_DeviceID];
        FDeviceToken = FPushService->DeviceTokenValue[TPushService_TDeviceTokenNames_DeviceToken];
    }
}

Re: The native push

PostPosted: Tue Mar 21, 2017 8:43 am
by Lena
Thank You very much!