iphone - 选项卡推送通知 cocos2d 游戏崩溃

标签 iphone ios cocos2d-iphone push-notification

我正在开发一款 box2d 游戏。在游戏中我使用的是 PushWoosh 推送通知。它工作正常(从 PushWoosh 服务器获取推送通知)但是当我点击推送通知时我的游戏崩溃了。在 Appdelegate 中这样实现

-在 Appdelegate.h 中:

    @interface AppDelegate:NSObject<UIApplicationDelegate,AdColonyDelegate,PushNotificationDelegate,UIAlertViewDelegate>{
        UIWindow            *window;
        RootViewController  *viewController;
        PushNotificationManager *pushManager;
    }
    @property (nonatomic, retain) PushNotificationManager *pushManager;
    @property (nonatomic, retain) UIWindow *window;
    @property (nonatomic, retain) RootViewController    *viewController;
    @end



    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
        // Init the window
    window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];


    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationType)(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];   

    //initialize push manager instance
    pushManager = [[PushNotificationManager alloc] initWithApplicationCode:@"PushWoosh App_ID" appName:@"App_Name" ];
     pushManager.delegate = self;
     [pushManager handlePushReceived:launchOptions];
    /*pushManager = [[PushNotificationManager alloc] initWithApplicationCode:@"FA7CF-665BF" navController:self.viewController appName:@"Cricket" ];
    pushManager.delegate = self;
    [pushManager handlePushReceived:launchOptions];*/

    // Try to use CADisplayLink director
    // if it fails (SDK < 3.1) use the default director
    if( ! [CCDirector setDirectorType:kCCDirectorTypeDisplayLink] )
        [CCDirector setDirectorType:kCCDirectorTypeDefault];


    CCDirector *director = [CCDirector sharedDirector];

    // Init the View Controller
    viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];
    viewController.wantsFullScreenLayout = YES;

    //
    // Create the EAGLView manually
    //  1. Create a RGB565 format. Alternative: RGBA8
    //  2. depth format of 0 bit. Use 16 or 24 bit for 3d effects, like CCPageTurnTransition
    //
    //
    EAGLView *glView = [EAGLView viewWithFrame:[window bounds]
                                   pixelFormat:kEAGLColorFormatRGB565   // kEAGLColorFormatRGBA8
                                   depthFormat:0                        // GL_DEPTH_COMPONENT16_OES
                        ];

    // attach the openglView to the director
    [director setOpenGLView:glView];

    // Enables High Res mode (Retina Display) on iPhone 4 and maintains low res on all other devices
    if (UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPad)
    {
        if( ! [director enableRetinaDisplay:YES] )
            CCLOG(@"Retina Display Not supported");
    }

    //
    // VERY IMPORTANT:
    // If the rotation is going to be controlled by a UIViewController
    // then the device orientation should be "Portrait".
    //
    // IMPORTANT:
    // By default, this template only supports Landscape orientations.
    // Edit the RootViewController.m file to edit the supported orientations.
    //
#if GAME_AUTOROTATION == kGameAutorotationUIViewController
    [director setDeviceOrientation:kCCDeviceOrientationPortrait];
#else
    [director setDeviceOrientation:kCCDeviceOrientationLandscapeRight];
#endif

    [director setAnimationInterval:1.0/60];
    [director setDisplayFPS:YES];


    // make the OpenGLView a child of the view controller
    [viewController setView:glView];

    // make the View Controller a child of the main window
    [window addSubview: viewController.view];

    [window makeKeyAndVisible];

    // Default texture format for PNG/BMP/TIFF/JPEG/GIF images
    // It can be RGBA8888, RGBA4444, RGB5_A1, RGB565
    // You can change anytime.
    [CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888];


    // Removes the startup flicker
    [self removeStartupFlicker];    


    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    if(![defaults integerForKey:@"First"]) {

        [[CCDirector sharedDirector]runWithScene:[MainMenu scene]];
    }
    else {

        [[CCDirector sharedDirector]runWithScene:[PlayAsGuestScene scene]];
    }


    return YES;
}

    - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{

         [pushManager handlePushReceived:userInfo];
}
   - (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken{
    [pushManager handlePushRegistration:deviceToken];

    //you might want to send it to your backend if you use remote integration
    NSString *token = [pushManager getPushToken];
}

在控制台我收到这个错误: * 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[AppDelegate onPushAccepted:]:无法识别的选择器发送到实例 0xf50d290”

为什么会这样?

最佳答案

我终于明白了。我改为

-(void)applicationDidFinishLaunching:(UIApplication*)application{

  pushManager = [[PushNotificationManager alloc] initWithApplicationCode:@"PushWoosh App_ID" appName:@"App_Name" ];
     pushManager.delegate = self;

}

-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{

         //write own code
}

我的应用运行正常,没有崩溃。

关于iphone - 选项卡推送通知 cocos2d 游戏崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12227057/

相关文章:

ios - IAP 检测 SK 警报 View

ios - 在 Cocos2d 中的 Sprites 制作的两点之间绘制一条线 Sprite

iphone - 如何实现像 iPhone 上的电子邮件地址那样的自动选择文本框?

ios - UITableView 空 View 放不下

ios - 将浮点变量作为参数传递

ios - 如何在 UIScrollView 中使用 UIGestureRecognizer

ios - UIToolBar 背景透明

ios - Swift:如何通过完成处理程序(闭​​包)的引用存储对象数组?

ios - CCTextField 编辑开始后屏幕移动

iphone - MonoTouch - 有人用过这个吗?