[aerogear-dev] [iOS] Cordova and AeroGear UnifiedPush

Matthias Wessendorf matzew at apache.org
Mon Jul 15 11:20:28 EDT 2013


On Mon, Jul 15, 2013 at 5:11 PM, Lucas Holmquist <lholmqui at redhat.com>wrote:

>
> On Jul 13, 2013, at 10:54 AM, Matthias Wessendorf <matzew at apache.org>
> wrote:
>
> Hi,
>
> today I played with Apache Cordova, the PushPlugin<https://github.com/phonegap-build/PushPlugin/tree/1.3.3>,
> AeroGear.js (Notifier branch) and our UnifiedPush Server.
>  <https://gist.github.com/matzew/1513378b4efb700da46f#setup>Setup
>
> These steps from the iOS Tutorial<http://aerogear.org/docs/guides/aerogear-push-ios/> are
> required for an iOS-Cordova app as well:
>
>    - Apple App ID and SSL Certificate for APNs
>    - Apple Provisioning Profile
>    - The AeroGear Unified Push Server
>
> TL;DR: You need a new App-ID, a SSL-cert and a provisioning profile (for
> that APP-ID). On the UnifiedPush Server, you need a PushApplication and
> an iOS Variant :-)
>  <https://gist.github.com/matzew/1513378b4efb700da46f#cordova-stuff>Cordova
> stuff <https://gist.github.com/matzew/1513378b4efb700da46f#pushplugin>
> PushPlugin
>
> Get the Cordova PushPlugin<https://github.com/phonegap-build/PushPlugin/tree/1.3.3> (there
> is a downloadable tarball) and extract the tarball to some location.
>  <https://gist.github.com/matzew/1513378b4efb700da46f#cordova-app>Cordova
> App
>
> Creating a Corodva app is simple:
>
> cordova create FolderOfTheApp com.my.id.AppName AppName
> cd FolderOfTheApp
> cordova platform add ios
> cordova plugin add folder_of_PushPlugin-1.3.3
>
> *HINT:* Make sure your Apple ID matches the above "com.my.id.AppName"
> value...
>
>    - Install aerogear.js (checkout (and build) the Notifier branch) and
>    jquery.min.js -> I basically copied the files into the "www" folder;
>
> afterwards build the project:
>
> cordova build
>
> Now open the generated Xcode project, and start "hacking".
>
>    - In the index.html<https://github.com/matzew/UPCordovaPlayings/blob/master/CordovaTest/platforms/ios/www/index.html> I
>    just linked the "required" JavaScript sources.
>    - The index.JS<https://github.com/matzew/UPCordovaPlayings/blob/master/CordovaTest/platforms/ios/www/js/index.js> contains
>    some JavaScript, that takes care of:
>       - Trigger the PushPlugin/UnifiedPush setup<https://github.com/matzew/UPCordovaPlayings/blob/master/CordovaTest/platforms/ios/www/js/index.js#L16>
>       - Setup of the Cordova PushPlugin<https://github.com/matzew/UPCordovaPlayings/blob/master/CordovaTest/platforms/ios/www/js/index.js#L53-L61>
>       - The received (APNs) device-token is "submitted" to the
>       UnifiedPush Server (using AeroGear.js)<https://github.com/matzew/UPCordovaPlayings/blob/master/CordovaTest/platforms/ios/www/js/index.js#L27-L48>
>       - Handling iOS/APNs notifications<https://github.com/matzew/UPCordovaPlayings/blob/master/CordovaTest/platforms/ios/www/js/index.js#L2-L4>
>
> This all works well. However, I had to do some "hack" to be able to use
> the registerWithPushServer()function:
>
> var tokenContainer = {};
> tokenContainer.channelID = deviceToken;
>
> That is because the JS does expect the token/channelID as the above
> ".channelID". I am sure that can be made a bit more flexible.
>
> Also, the "metadata" currently is only able to specify the following
> values:
>
>    - deviceToken
>    - alias
>    - category
>
> I am sure we can make it more generic here as well.
>
> So again, without too much work, I got it working:
> https://twitter.com/mwessendorf/status/356027736780836865
>
> However I had some issues.
>  <https://gist.github.com/matzew/1513378b4efb700da46f#pushplugin-1>
> PushPlugin:
>
> I had to copy the ObjC bits by hand. See here<https://github.com/phonegap-build/PushPlugin/issues/34>
> .
>  <https://gist.github.com/matzew/1513378b4efb700da46f#aerogearjs>
> AeroGear.js
>
>    -
>
>    Uncaught TypeError: Cannot read property 'simplePushServerURL' of
>    undefined aerogear.js:955 (anonymous function) aerogear.js:955 (anonymous
>    function)
>    - at least in the browser.... However, I could remove it, on the
>       Corodva app .... and the app still seams to work.... So, not sure :-)
>    -
>
>    looks like the Notifier branch requires sockjs Uncaught
>    ReferenceError: SockJS is not defined aerogear.js:942 (anonymous function)
>    - But again in the browser...., I could remove that "import" in my
>       Cordova app. So, not sure here too :-)
>
> The (ugly) code is posted on my GH account<https://github.com/matzew/UPCordovaPlayings>
> .
>
> I guess we could convert this into a more "official" guide/tutorial at
> some point. This email should give some hints on getting started.
>
> Another question:
>
> Perhaps we want to fork the PushPlugin and stick our AeroGear.js bits in
> there? So that all is ready ? I am not sure, just some idea.
>
> So This plugin is actually part of phone gap build,  Which means people
> can get it easy.  but at the same time,  these types of plugins aren't as
> fast to upgrade
>
> They include an example ruby "push server" in the example code.
>

Ah :-) So, if there are other plugins, let me know :) I just picked that
one for my tests




>
>
> I'm not sure how others feel about it,  but i can be convinced of forking
> a copy,  and then adding in our stuff,  as well as adding a "FFOS" version
> that we could maybe contribute back upstream.
>


I am also fine with (for now) just having "instructions", that should
pretty much do the trick - at least I was also able to use it that way.
(Android try-out will follow "soon")


>
> In one of the Phone Gap Day workshops, they are going to be talking about
> push notifications. so i'll report back.
>

sweet! I am happy to hear more on what you've learned / heard there.

Thanks for the feedback, Luke!

-M


>
> Feedback welcome!
>
> --
> Matthias Wessendorf
>
> blog: http://matthiaswessendorf.wordpress.com/
> sessions: http://www.slideshare.net/mwessendorf
> twitter: http://twitter.com/mwessendorf
> _______________________________________________
> aerogear-dev mailing list
> aerogear-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/aerogear-dev
>
>
>
> _______________________________________________
> aerogear-dev mailing list
> aerogear-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/aerogear-dev
>



-- 
Matthias Wessendorf

blog: http://matthiaswessendorf.wordpress.com/
sessions: http://www.slideshare.net/mwessendorf
twitter: http://twitter.com/mwessendorf
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/aerogear-dev/attachments/20130715/341984e6/attachment.html 


More information about the aerogear-dev mailing list