Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Push notification drop-in unit



Permlink Replies: 14 - Last Post: Sep 28, 2014 9:43 AM Last Post By: giuseppe magistro Threads: [ Previous | Next ]
Dave Nottage

Posts: 1,850
Registered: 1/7/00
Push notification drop-in unit
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 12, 2013 8:19 PM
I've posted a small demo to the attachments group that includes the unit:

Apple.RemoteNotification

Which is a drop-in unit that has the necessary code to support receiving push notifications in iOS apps. The unit is a
culmination of ideas, based partly around the demo in this video:

http://www.youtube.com/watch?v=duAzLQJ898g

The main difference being that there's no need to modify the existing FMX.Platform.iOS unit; all the code required is
in the Apple.RemoteNotification unit. Note that the demo and unit merely does the work of registering for push
notifications; there's no code for handling errors, changing badge number etc, nor any server code.

Hopefully it's fairly self-explanatory, however I'll do my best to field questions about it.

--
Dave Nottage [TeamB]
Yegor Kurbachev

Posts: 7
Registered: 12/1/11
Re: Push notification drop-in unit
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 13, 2013 8:17 AM   in response to: Dave Nottage in response to: Dave Nottage
Dave Nottage wrote:
Which is a drop-in unit that has the necessary code to support receiving push notifications in iOS apps.

Hi!

Your solution is incomplete. If your app was started as a result of a push notification being received (not push notification being received while your app was already running), your OnReceive event would never be called. To continue NOT changing the FMX.Platform.iOS you need to use NSNotificationCenter and register for UIApplicationDidFinishLaunchingNotification (iOS) or NSApplicationDidFinishLaunchingNotification (Mac).

Sorry to self-advertise, but that's exactly the way I have implemented this in my components suite: https://forums.embarcadero.com/thread.jspa?threadID=90443

Note that the demo and unit merely does the work of registering for push notifications; there's no code for handling errors, changing badge number etc, nor any server code.

And, back to the self-advertising, apart from the generic push notification component, my suite also has complete integration with the (mostly free) PushWoosh service, thus you get the full solution, including statistics, obsolete devices removal, etc.

Regards,
Yegor

P.S.: If such self-advertising is inappropriate (even though I think I have supplemented it with the missing bit for free :) ), let me know and this will not happen again.
Dave Nottage

Posts: 1,850
Registered: 1/7/00
Re: Push notification drop-in unit
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 13, 2013 4:07 PM   in response to: Yegor Kurbachev in response to: Yegor Kurbachev
Yegor Kurbachev wrote:

If your app was started as a result of a push notification being received (not push notification being received while
your app was already running), your OnReceive event would never be called. To continue NOT changing the
FMX.Platform.iOS you need to use NSNotificationCenter and register for UIApplicationDidFinishLaunchingNotification
(iOS) or NSApplicationDidFinishLaunchingNotification (Mac).

Thanks for the tip! I haven't actually used the OnReceive event, so I wouldn't have come across it, yet :-)

--
Dave Nottage [TeamB]
Dave Nottage

Posts: 1,850
Registered: 1/7/00
Re: Push notification drop-in unit
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 13, 2013 9:40 PM   in response to: Dave Nottage in response to: Dave Nottage
I wrote:

Thanks for the tip!

Updated demo/unit in the attachments group.

--
Dave Nottage [TeamB]
Guest
Re: Push notification drop-in unit
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 22, 2013 9:08 PM   in response to: Dave Nottage in response to: Dave Nottage
Dave Nottage wrote:
I wrote:

Thanks for the tip!

Updated demo/unit in the attachments group.

--
Dave Nottage [TeamB]

Hello Dave,

thank you for the push notification demo in the attachment. I have tested the second version. It works very fine, but I have problems to read out the content of the push notification if the app ist started over the click on the push notification. If I will get the infos from FNotification in the second example, I get an access violation. Please can you tell me, if I can read out the content of the push notification if the app is started ?

--
Rolf Warnecke
http://www.code-orakel.de
http://www.bis-programmierung.de
Dave Nottage

Posts: 1,850
Registered: 1/7/00
Re: Push notification drop-in unit
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 22, 2013 9:24 PM   in response to: Guest in response to: Guest
Rolf Warnecke wrote:

If I will get the infos from FNotification in the second example, I get an access violation. Please can you tell me,
if I can read out the content of the push notification if the app is started ?

Where does the access violation occur?

--
Dave Nottage [TeamB]
Find tips and code samples at Delphi Worlds:
http://delphi.radsoft.com.au/blog
Guest
Re: Push notification drop-in unit
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 22, 2013 11:08 PM   in response to: Dave Nottage in response to: Dave Nottage
Dave Nottage wrote:

Where does the access violation occur?
Hello Dave,

thank you for your fast reply. In this sample code I get the access violation :
var
  UserInfo: NSDictionary;
begin
  if Assigned(FNotification) then
  begin
    UserInfo := FNotification.userInfo;  // <-- here I get the access violation
  end;
end; 

If I delete the line with UserInfo the app works.

--
Rolf Warnecke
http://www.code-orakel.de
http://www.bis-programmierung.de
Dave Nottage

Posts: 1,850
Registered: 1/7/00
Re: Push notification drop-in unit
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 22, 2013 11:26 PM   in response to: Guest in response to: Guest
Rolf Warnecke wrote:

var
UserInfo: NSDictionary;
begin
if Assigned(FNotification) then
begin
UserInfo := FNotification.userInfo; // <-- here I get the access violation
end;
end;

It seems that the FNotification reference has become invalid (i.e. not nil, but it doesn't point to anything). I might
need to have a test case to find out why.

--
Dave Nottage [TeamB]
Find tips and code samples at Delphi Worlds:
http://delphi.radsoft.com.au/blog
giuseppe magistro

Posts: 69
Registered: 2/21/05
Re: Push notification drop-in unit
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 9, 2014 6:39 PM   in response to: Dave Nottage in response to: Dave Nottage
Hi Dave,

i ported your unit apple.remotenotification.pas on xe6 and is working commenting a little part on fmx.platform.ios.pas.

// class_addMethod(appDelegateClass, sel_getUid('application:didReceiveRemoteNotification:'),
// @didReceiveRemoteNotification, 'v@:@@');
// class_addMethod(appDelegateClass, sel_getUid('application:didRegisterForRemoteNotificationsWithDeviceToken:'),
// @didRegisterForRemoteNotificationsWithDeviceToken, 'v@:@@');
// class_addMethod(appDelegateClass, sel_getUid('application:didFailToRegisterForRemoteNotificationsWithError:'),
// @didFailToRegisterForRemoteNotificationsWithError, 'v@:@@');

I do not want to use the indirect baas solution .

i look for a more clean solution than modify again fmx.platform.ios.pas.

Do you have any idea regarding this ?

Thanks in advance

Beppe

Asaf Goldman

Posts: 42
Registered: 4/29/09
Re: Push notification drop-in unit
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 11, 2014 12:50 PM   in response to: giuseppe magistro in response to: giuseppe magistro
I think that not everyone would like to use BaaS for push notifications and that embarcadero should provide us with a full set of components of APN and GCM both for app client for reviving messages and server components for sending them to Apple and Google.

Thanks
Asaf
Steven Wiberg

Posts: 28
Registered: 3/6/12
Re: Push notification drop-in unit
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 13, 2014 8:26 AM   in response to: Asaf Goldman in response to: Asaf Goldman
Asaf Goldman wrote:
I think that not everyone would like to use BaaS for push notifications and that embarcadero should provide us with a full set of components of APN and GCM both for app client for reviving messages and server components for sending them to Apple and Google.

Thanks
Asaf

I agree I would like to be able to have my own server installed on my computer setup to register devices to and send push notifications not having to use the BaaS that they have provided.
giuseppe magistro

Posts: 69
Registered: 2/21/05
Re: Push notification drop-in unit
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 14, 2014 7:36 AM   in response to: Steven Wiberg in response to: Steven Wiberg
Steven Wiberg wrote:
Asaf Goldman wrote:
I think that not everyone would like to use BaaS for push notifications and that embarcadero should provide us with a full set of components of APN and GCM both for app client for reviving messages and server components for sending them to Apple and Google.

Thanks
Asaf

I agree I would like to be able to have my own server installed on my computer setup to register devices to and send push notifications not having to use the BaaS that they have provided.

i totally agree !!!
Beppe
salim tekin

Posts: 2
Registered: 2/15/07
Re: Push notification drop-in unit
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 11, 2014 8:17 AM   in response to: giuseppe magistro in response to: giuseppe magistro
giuseppe magistro wrote:
Hi Dave,

i ported your unit apple.remotenotification.pas on xe6 and is working commenting a little part on fmx.platform.ios.pas.

// class_addMethod(appDelegateClass, sel_getUid('application:didReceiveRemoteNotification:'),
// @didReceiveRemoteNotification, 'v@:@@');
// class_addMethod(appDelegateClass, sel_getUid('application:didRegisterForRemoteNotificationsWithDeviceToken:'),
// @didRegisterForRemoteNotificationsWithDeviceToken, 'v@:@@');
// class_addMethod(appDelegateClass, sel_getUid('application:didFailToRegisterForRemoteNotificationsWithError:'),
// @didFailToRegisterForRemoteNotificationsWithError, 'v@:@@');

I do not want to use the indirect baas solution .

i look for a more clean solution than modify again fmx.platform.ios.pas.

Do you have any idea regarding this ?

Thanks in advance

Beppe


Hi are you modify fmx.platform.ios.pas.i dont use indirect baas solution.can you help me

giuseppe magistro

Posts: 69
Registered: 2/21/05
Re: Push notification drop-in unit
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 11, 2014 1:46 PM   in response to: salim tekin in response to: salim tekin
salim tekin wrote:
giuseppe magistro wrote:
Hi Dave,

i ported your unit apple.remotenotification.pas on xe6 and is working commenting a little part on fmx.platform.ios.pas.

// class_addMethod(appDelegateClass, sel_getUid('application:didReceiveRemoteNotification:'),
// @didReceiveRemoteNotification, 'v@:@@');
// class_addMethod(appDelegateClass, sel_getUid('application:didRegisterForRemoteNotificationsWithDeviceToken:'),
// @didRegisterForRemoteNotificationsWithDeviceToken, 'v@:@@');
// class_addMethod(appDelegateClass, sel_getUid('application:didFailToRegisterForRemoteNotificationsWithError:'),
// @didFailToRegisterForRemoteNotificationsWithError, 'v@:@@');

I do not want to use the indirect baas solution .

i look for a more clean solution than modify again fmx.platform.ios.pas.

Do you have any idea regarding this ?

Thanks in advance

Beppe


Hi are you modify fmx.platform.ios.pas.i dont use indirect baas solution.can you help me


Hi,
you can use the demo above and comment the part of fmx.platform.ios.pas as specified above here

beppe
giuseppe magistro

Posts: 69
Registered: 2/21/05
Re: Push notification drop-in unit
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 28, 2014 9:43 AM   in response to: giuseppe magistro in response to: giuseppe magistro
giuseppe magistro wrote:
salim tekin wrote:
giuseppe magistro wrote:
Hi Dave,

i ported your unit apple.remotenotification.pas on xe6 and is working commenting a little part on fmx.platform.ios.pas.

// class_addMethod(appDelegateClass, sel_getUid('application:didReceiveRemoteNotification:'),
// @didReceiveRemoteNotification, 'v@:@@');
// class_addMethod(appDelegateClass, sel_getUid('application:didRegisterForRemoteNotificationsWithDeviceToken:'),
// @didRegisterForRemoteNotificationsWithDeviceToken, 'v@:@@');
// class_addMethod(appDelegateClass, sel_getUid('application:didFailToRegisterForRemoteNotificationsWithError:'),
// @didFailToRegisterForRemoteNotificationsWithError, 'v@:@@');

I do not want to use the indirect baas solution .

i look for a more clean solution than modify again fmx.platform.ios.pas.

Do you have any idea regarding this ?

Thanks in advance

Beppe


Hi are you modify fmx.platform.ios.pas.i dont use indirect baas solution.can you help me


Hi,
you can use the demo above and comment the part of fmx.platform.ios.pas as specified above here

beppe

hi all ! same modification on xe7 and notifications works

beppe
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02