2012-09-11 63 views
1

過去幾週一直試圖在Phonegap 2基本應用中設置PushNotification。phonegap 2.0推送通知插件iOS設置(一個接一個出錯)

這裏我已經完成的步驟。

  1. 拖動PushNotification文件夾,插件文件夾:

    http://joelchu.com/wp-content/uploads/2012/09/1.png

  2. 按照每個文檔下面的指令

    http://joelchu.com/wp-content/uploads/2012/09/2.png

  3. 添加PushNotifcation/PushNotification到Cordova.plist插件部分

  4. 修改AppDelegate.m

    - (void) dealloc 
    { 
        [super dealloc]; 
    } 
    
    /* START PUSH MODIFCATION */ 
    
    #pragma PushNotification delegation 
    
    - (void)application:(UIApplication*)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken 
    { 
        PushNotification* pushHandler = [self.viewController getCommandInstance:@"PushNotification"]; 
        [pushHandler didRegisterForRemoteNotificationsWithDeviceToken:deviceToken]; 
    } 
    
    - (void)application:(UIApplication*)app didFailToRegisterForRemoteNotificationsWithError:(NSError*)error 
    { 
        PushNotification* pushHandler = [self.viewController getCommandInstance:@"PushNotification"]; 
        [pushHandler didFailToRegisterForRemoteNotificationsWithError:error]; 
    } 
    
    - (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo 
    { 
        PushNotification* pushHandler = [self.viewController getCommandInstance:@"PushNotification"]; 
        NSMutableDictionary* mutableUserInfo = [userInfo mutableCopy]; 
    
        // Get application state for iOS4.x+ devices, otherwise assume active 
        UIApplicationState appState = UIApplicationStateActive; 
        if ([application respondsToSelector:@selector(applicationState)]) { 
         appState = application.applicationState; 
        } 
    
        [mutableUserInfo setValue:@"0" forKey:@"applicationLaunchNotification"]; 
        if (appState == UIApplicationStateActive) { 
         [mutableUserInfo setValue:@"1" forKey:@"applicationStateActive"]; 
         [pushHandler didReceiveRemoteNotification:mutableUserInfo]; 
        } else { 
         [mutableUserInfo setValue:@"0" forKey:@"applicationStateActive"]; 
         [mutableUserInfo setValue:[NSNumber numberWithDouble: [[NSDate date] timeIntervalSince1970]] forKey:@"timestamp"]; 
         [pushHandler.pendingNotifications addObject:mutableUserInfo]; 
        } 
    } 
    
    /* END PUSH MODIFICATION */ 
    
    @end 
    

第一個錯誤

未知類型名稱PushNotification

所以我剛過了上次導入加入這一行:

#import "PushNotification.h" 

解決了這個問題。

下一個問題

CDVPlugin.h找不到文件

所以我以下內容添加到用戶頭搜索路徑 - 以所有構建設置:

$(CORDOVALIB)/Classes (recursive) 

下一個問題

然後它拋出了20多個錯誤!

http://joelchu.com/wp-content/uploads/2012/09/3.png

我做了什麼錯?

一直在上下尋找。令我驚訝的是似乎沒有人有問題。

更多關於我的設置:

  • 的PhoneGap 2.0
  • 的XCode 4。5(預覽4)
  • 的iOS 6基地(應用程序建立的iOS 5及以上)

希望有人在那裏得到了一個答案。謝謝。

(如附註:在PhoneGap的PushNotification插件被打破 - 他們沒有連續4個月已經再次更新是否有任何免費的替代感謝。?)

我所描述的my blog同樣的問題。

固定(NOW)

固定

/* START BLOCK */ 

#pragma PushNotification delegation 

- (void) application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken 
{ 
    PushNotification* pushHandler = [self.viewController getCommandInstance:@"PushNotification"]; 
    [pushHandler didRegisterForRemoteNotificationsWithDeviceToken:deviceToken]; 
} 

- (void) application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error 
{ 
    PushNotification* pushHandler = [self.viewController getCommandInstance:@"PushNotification"]; 
    [pushHandler didFailToRegisterForRemoteNotificationsWithError:error]; 
} 

- (void) application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo 
{ 
    PushNotification* pushHandler = [self.viewController getCommandInstance:@"PushNotification"]; 
    NSMutableDictionary* mutableUserInfo = [userInfo mutableCopy]; 

    // Get application state for iOS4.x+ devices, otherwise assume active 
    UIApplicationState appState = UIApplicationStateActive; 
    if ([application respondsToSelector:@selector(applicationState)]) { 
     appState = application.applicationState; 
    } 

    [mutableUserInfo setValue:@"0" forKey:@"applicationLaunchNotification"]; 
    if (appState == UIApplicationStateActive) { 
     [mutableUserInfo setValue:@"1" forKey:@"applicationStateActive"]; 
     [pushHandler didReceiveRemoteNotification:mutableUserInfo]; 
    } else { 
     [mutableUserInfo setValue:@"0" forKey:@"applicationStateActive"]; 
     [mutableUserInfo setValue:[NSNumber numberWithDouble: [[NSDate date] timeIntervalSince1970]] forKey:@"timestamp"]; 
     [pushHandler.pendingNotifications addObject:mutableUserInfo]; 
    } 
} 

/* STOP BLOCK */ 

我所做的 - 前兩個

- (void)application:(UIApplication*)app

改爲

- (void) application:(UIApplication*)application

我移動

#import "PushNotification.h"

到塊的頭(而不僅僅是修改代碼之前 - 在上下文中的問題,原因@end沒有)。

我還沒有運行JavaScript界面​​。但所有的錯誤都消失了。

謝謝。

回答

2

請嘗試通過這條線

#import <Cordova/CDVPlugin.h> 

恢復您的更改進口,然後替換該塊

#ifdef CORDOVA_FRAMEWORK 
    #import <Cordova/CDVPlugin.h> 
#else 
    #import "CDVPlugin.h" 
#endif 

如果仍然不能正常工作,你可能沒有的PhoneGap 2.0項目或你安裝了錯誤或多個版本的框架。

您可以在「PushNotification.m」文件中執行同樣的操作:只需用#import <Cordova/JSONKit.h>替換第二個導入即可。

請注意,我還沒有使用該插件,這只是從我移植到2.0的經驗(我是製表符/導航欄插件的作者)。

+0

感謝您的回答。你在這裏說了什麼,並且錯誤從20減少到了5.我將在稍後更新關於錯誤的更多信息。 –