Приложение Phonegap с проблемами городского дирижабля - PullRequest
3 голосов
/ 16 марта 2012

Я пытаюсь интегрировать 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 в мою папку PhoneGap. Поддерживаемые файлы, включая AirshipConfig.plist. Также я установил пути поиска заголовка в настройках сборки для папки Airship, что я скопировал ранее в папку проекта xCode.

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

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

Ответы [ 2 ]

6 голосов
/ 24 октября 2012

Вам нужно импортировать как UAirship.h & UAPush.h в ваш AppDelegate.m

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

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

3 голосов
/ 11 апреля 2012

Посмотрите сервисы Xtify push, плагин 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

...