Приложение Phonegap с проблемами городского дирижабля

Я пытаюсь интегрировать Push-уведомления в свое приложение для iOS. Это проект Phonegap/Cordova. Все работает хорошо, без APNS и Urban Airship.

Что я сделал до сих пор? У меня получилось, что я могу отправить Push-сообщение от UA на свой телефон, но это было сделано с примером кода с разных форумов, а не с документами UA. Итак, я начинаю делать это так, как показано в документах UA. С этим я очень смущен и много пробовал.

Итак, я сделал следующее: взял пример Push из UA и скопировал код в AppDelegate.m, который теперь выглядит так:

 // 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];
}

Это почти то же самое, что и раньше, но предоставлено UA. Затем я скопировал файлы из папки других источников из Push Sample в папку Supported Files моей телефонной щели, включая AirshipConfig.plist. Также я установил пути поиска заголовков в настройках сборки в папку Airship, которую я скопировал ранее в папку проекта xCode.

Теперь я получаю сообщение об ошибке (6) «Использование необъявленного идентификатора UAPush» в файле AppDeledate.m. Что я могу сделать сейчас?

Спасибо за помощь...


person Jeronimo79    schedule 16.03.2012    source источник
comment
У меня тоже было много проблем с PhoneGap и UrbanAirship. В итоге я отказался от их совместного использования, когда UrbanAirship сказал мне, что они не будут поддерживать PhoneGap, даже если я получил код с их сайта.   -  person Will Larche    schedule 01.04.2012


Ответы (2)


Вам необходимо импортировать UAirship.h и UAPush.h в свой AppDelegate.m.

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

Это избавит вас от проблемы с необъявленным идентификатором. Глупый городской дирижабль забыл поместить это в свою документацию

person scotsqueakscoot    schedule 24.10.2012
comment
Могу проверить это как правду, я понятия не имею, почему он не принял ваш ответ ... избавил меня от головной боли, спасибо! ПРИМЕЧАНИЕ. По состоянию на 12.04.13 все еще отсутствует в документах. - person roozbubu; 13.04.2013

Взгляните на push-сервисы Xtify, плагин PhoneGap полностью поддерживается:

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

person Michael Bordash    schedule 11.04.2012