The native push

This is the forum for miscellaneous technical/programming questions.

Moderator: 2ffat

The native push

Postby Lena » Sat Mar 18, 2017 7:50 am

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++.
Lena
BCBJ Master
BCBJ Master
 
Posts: 417
Joined: Sun Feb 06, 2011 1:28 pm

Re: The native push

Postby Lena » Mon Mar 20, 2017 8:06 am

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);
Lena
BCBJ Master
BCBJ Master
 
Posts: 417
Joined: Sun Feb 06, 2011 1:28 pm

Re: The native push

Postby rlebeau » Mon Mar 20, 2017 1:59 pm

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];
    }
}
Remy Lebeau (TeamB)
Lebeau Software
User avatar
rlebeau
BCBJ Author
BCBJ Author
 
Posts: 1375
Joined: Wed Jun 01, 2005 3:21 am
Location: California, USA

Re: The native push

Postby Lena » Tue Mar 21, 2017 8:43 am

Thank You very much!
Lena
BCBJ Master
BCBJ Master
 
Posts: 417
Joined: Sun Feb 06, 2011 1:28 pm


Return to Technical

Who is online

Users browsing this forum: Bing [Bot], Yahoo [Bot] and 3 guests

cron