Phonegap app with urban airship problems

I am trying to integrate Push Notifications in my iOS app. This is a Phonegap / Cordova project. Everything works well, without APNS and the city airship.

What have I done so far? I got it to work so I could send a Push message from UA to my phone, but that was done with sample code from various forums, not UA docs. So I start doing it like in the UA docs. With this I got very confused and tried a lot.

So what I did was take Push Push from UA and copied the code to AppDelegate.m, which now looks like this:

 // Create Airship singleton that 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 much the same as before, but given by UA. Then I copied the files from another source folder from Push Sample to my phone folder. Supported files, including AirshipConfig.plist. Also I set the header search paths in build settings to the Airship folder which I copied earlier to the xCode project folder.

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

Thanks for the help...

+3


source to share


2 answers


You need to import both UAirship.h and UAPush.h into AppDelegate.m

#import "MainViewController.h"
#import "UAirship.h"
#import "UAPush.h"

      



This will save you the outstanding ID issue. Silly Urban Airship forgot to put this in their documentation

+6


source


Take a look at the Xtify push services, the PhoneGap plugin is fully supported:

IOS: http://developer.xtify.com/display/sdk/PhoneGap+for+iOS+Xtify+Integration+Guide



Android: http://developer.xtify.com/display/sdk/PhoneGap+for+Android+Xtify+Integration+Guide

+3


source







All Articles