具有城市飞艇问题的Phonegap应用程序

Jer*_*o79 3 xcode apple-push-notifications urbanairship.com cordova

我试图在我的iOS应用程序中集成推送通知.这是一个Phonegap/Cordova项目.没有APNS和Urban Airship,一切运作良好.

我到现在为止做了什么?我得到了它的工作,我可以从UA向我的手机发送推送消息,但这是通过不同论坛的示例代码完成的,而不是UA文档.所以我开始像在UA的文档中那样做.我非常困惑,尝试了很多.

所以我做了以下操作:从UA获取Push Sample并将代码复制到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];
}
Run Code Online (Sandbox Code Playgroud)

它和以前一样,但是来自UA.然后我将其他sources文件夹中的文件从Push Sample复制到我的phonegap文件夹支持的文件,包括AirshipConfig.plist.另外,我将Build Settings中的Header Search Paths设置为Airship文件夹,这是我之前复制到xCode项目文件夹中的内容.

现在我在AppDeledate.m文件中得到错误(6)"使用未声明的标识符'UAPush'".我现在能做什么?

谢谢你的帮助......

sco*_*oot 6

您需要在AppDelegate.m中导入UAirship.h和UAPush.h

#import "MainViewController.h"
#import "UAirship.h"
#import "UAPush.h"
Run Code Online (Sandbox Code Playgroud)

这将消除您未申报的标识符问题.傻城市飞艇忘了把它放在他们的文档中