Phonegap App with Urban Airship Problems

435 views
Skip to first unread message

Jeronimo79

unread,
Mar 19, 2012, 2:06:55 AM3/19/12
to phon...@googlegroups.com
Hello together,

Im trying to integrate Push Notifications in my iOS App. This is a Phonegap/Cordova Project. Everything is working well, without the APNS and Urban Airship.

What I have done till now? I got it to work, that I could send a Push Message from UA to my phone, but that was done with sample code from different forums and not the UA docs. So I startet to do it like in the docs of UA is showed. With that Im very confused and tried a lot.

So i did following:Took the Push Sample from UA and copied the code to AppDelegate.m what looks now like this:

// Create Airship singleton that's used to talk to Urban Airhship servers.
   
// Please populate AirshipConfig.plist with your info from http://go.urbanairship.com
   
[UAirship takeOff:takeOffOptions];

   
[[UAPush shared] resetBadge];//zero badge on startup

   
[[UAPush shared] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
                                                         
UIRemoteNotificationTypeSound |
                                                         
UIRemoteNotificationTypeAlert)];

   
return YES;
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
    UALOG
(@"Application did become active.");
   
[[UAPush shared] resetBadge]; //zero badge when resuming from background (iOS 4+)
}

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    UALOG
(@"APN device token: %@", deviceToken);
   
// Updates the device token and registers the token with UA
   
[[UAPush shared] registerDeviceToken:deviceToken];


   
/*
     * Some example cases where user notification may be warranted
     *
     * This code will alert users who try to enable notifications
     * from the settings screen, but cannot do so because
     * notications are disabled in some capacity through the settings
     * app.
     *
     */


   
/*

     //Do something when notifications are disabled altogther
     if ([application enabledRemoteNotificationTypes] == UIRemoteNotificationTypeNone) {
     UALOG(@"iOS Registered a device token, but nothing is enabled!");

     //only alert if this is the first registration, or if push has just been
     //re-enabled
     if ([UAirship shared].deviceToken != nil) { //already been set this session
     NSString* okStr = @"OK";
     NSString* errorMessage =
     @"Unable to turn on notifications. Use the \"Settings\" app to enable notifications.";
     NSString *errorTitle = @"Error";
     UIAlertView *someError = [[UIAlertView alloc] initWithTitle:errorTitle
     message:errorMessage
     delegate:nil
     cancelButtonTitle:okStr
     otherButtonTitles:nil];

     [someError show];
     [someError release];
     }

     //Do something when some notification types are disabled
     } else if ([application enabledRemoteNotificationTypes] != [UAPush shared].notificationTypes) {

     UALOG(@"Failed to register a device token with the requested services. Your notifications may be turned off.");

     //only alert if this is the first registration, or if push has just been
     //re-enabled
     if ([UAirship shared].deviceToken != nil) { //already been set this session

     UIRemoteNotificationType disabledTypes = [application enabledRemoteNotificationTypes] ^ [UAPush shared].notificationTypes;



     NSString* okStr = @"OK";
     NSString* errorMessage = [NSString stringWithFormat:@"Unable to turn on %@. Use the \"Settings\" app to enable these notifications.", [UAPush pushTypeString:disabledTypes]];
     NSString *errorTitle = @"Error";
     UIAlertView *someError = [[UIAlertView alloc] initWithTitle:errorTitle
     message:errorMessage
     delegate:nil
     cancelButtonTitle:okStr
     otherButtonTitles:nil];

     [someError show];
     [someError release];
     }
     }

     */

}

- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *) error {
    UALOG
(@"Failed To Register For Remote Notifications With Error: %@", error);
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
    UALOG
(@"Received remote notification: %@", userInfo);

   
// Get application state for iOS4.x+ devices, otherwise assume active
   
UIApplicationState appState = UIApplicationStateActive;
   
if ([application respondsToSelector:@selector(applicationState)]) {
        appState
= application.applicationState;
   
}

   
[[UAPush shared] handleNotification:userInfo applicationState:appState];
   
[[UAPush shared] resetBadge]; // zero badge after push received
}

- (void)applicationWillTerminate:(UIApplication *)application {
   
[UAirship land];
}

Its pretty the same like before, but given from UA. Then i copied the files from the other sources folder from the Push Sample into my phonegap folder Supported Files including the AirshipConfig.plist. Also I set the Header Search Paths in the Build Settings to the Airship folder, what i copied before into the xCode project folder.

Now I get the error (6) "Use of undeclared identifier 'UAPush'" in the AppDeledate.m file. What can I do now?

Thanks for some help...

surfjedi

unread,
Mar 28, 2012, 12:15:43 AM3/28/12
to phon...@googlegroups.com
Im looking for some help on this same thing, getting notifications plugin or something else to use Urban airship with cordova.  I had it working in PG 1.3.0, but since the cordova 1.5 i can't get it to work.

thanks if an gone knows..

Chris Brody

unread,
Mar 28, 2012, 8:37:02 AM3/28/12
to phon...@googlegroups.com
To be honest I found it a little easier to do this myself in AppDelegate.m. I found an excellent tutorial: http://www.raywenderlich.com/3443/apple-push-notification-services-tutorial-part-12

Mark Bice

unread,
May 14, 2012, 2:19:43 PM5/14/12
to phon...@googlegroups.com
This guy got the UA/PG plugin working against 1.6.0. I tested against 1.7.0 and it worked just fine for me.

Reply all
Reply to author
Forward
Message has been deleted
0 new messages