2012-03-16 54 views
3

我試圖將推送通知集成到我的iOS應用程序中。這是Phonegap/Cordova項目。一切都很好,沒有APNS和城市飛艇。Phonegap應用程序與城市飛艇問題

我到現在爲止做了什麼?我得到它的工作,我可以從UA發送推送消息到我的手機,但是這是用來自不同論壇的示例代碼而不是UA文檔完成的。所以我開始像在UA文檔中那樣做。那個我很困惑,並且嘗試了很多。

所以我做了以下內容:從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的其他源文件夾中的文件複製到我的phonegap文件夾中,包括AirshipConfig.plist。此外,我將「構建設置」中的標題搜索路徑設置爲Airship文件夾,我之前將其複製到xCode項目文件夾中。

現在我在AppDeledate.m文件中出現錯誤(6)「使用未聲明的標識符'UAPush'」。我現在能做什麼?

感謝一些幫助......

+1

我也有很多PhoneGap和UrbanAirship的問題。當UrbanAirship告訴我他們不會支持PhoneGap時,我最終放棄了使用它們,即使我從他們的網站獲得了代碼。 – 2012-04-01 01:00:24

回答

6

你需要在AppDelegate.m中導入UAirship.h & UAPush.h

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

這將消除您的未聲明的標識符問題。傻城市飛艇忘了把它放在他們的文檔

+0

可以驗證這是真實的,我不知道他爲什麼沒有接受你的答案...救了我主要的頭痛,謝謝!注:截至4/12/13仍然沒有在文檔中 – roozbubu 2013-04-12 21:20:07