本地推送通知不适用于实时应用

时间:2015-01-04 13:20:46

标签: ios iphone notifications push-notification uilocalnotification

我创建了一个游戏,当他们通过测试航班发送我的版本时(在itunes连接之外)它正常工作,我得到本地推送通知 - 也提示询问我是否要允许推送通知。

然而,当游戏上传到itunes connect并且我从那里下载本地推送通知不起作用时,我也没有收到要求允许来自此游戏的通知的消息。

有关它为什么在itunes之外工作的任何想法连接,但不是从appstore下载或从itunes预发布时。?

通知似乎是由以下人员提出的:

- (void) sendLocalReminder:(NSDate *)date  Type:(NSString*)type Alert:(NSString *)title{
    // some code ...
    UILocalNotification *localNotif = [[UILocalNotification alloc] init];

    if (localNotif == nil)
        return;

    localNotif.fireDate = date;
    localNotif.timeZone = [NSTimeZone defaultTimeZone];
    localNotif.alertAction = NSLocalizedString(@"Reminder", nil);
    localNotif.alertBody = title;
    localNotif.soundName = UILocalNotificationDefaultSoundName;
    localNotif.applicationIconBadgeNumber = 0;

    NSDictionary *infoDict = [NSDictionary dictionaryWithObject:type forKey:@"lid"];
    localNotif.userInfo = infoDict;

    [[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
    [localNotif release];

}

-(void)notifyScratch
{
    [self sendLocalReminder:[NSDate dateWithTimeIntervalSinceNow:TIME_LIFE_BONUS] Type:LNT_SCRATCH_CARD Alert:LNM_SCRATCH_CARD];
}

AppDelegate.h

//
//  
//  
//
//  Created by HuangYinHui on 11/12/14.
//  Copyright __MyCompanyName__ 2014. All rights reserved.
//

#ifndef  _APP_DELEGATE_H_
#define  _APP_DELEGATE_H_

#include "CCApplication.h"

/**
@brief    The cocos2d Application.

The reason to implement with private inheritance is to hide some interface details of CCDirector.
*/
class  AppDelegate : private cocos2d::CCApplication
{
public:
    AppDelegate();
    virtual ~AppDelegate();

    /**
    @brief    Implement CCDirector and CCScene init code here.
    @return true    Initialize success, app continue.
    @return false   Initialize failed, app terminate.
    */
    virtual bool applicationDidFinishLaunching();

    /**
    @brief  The function is called when the application enters the background
    @param  the pointer of the application instance
    */
    virtual void applicationDidEnterBackground();

    /**
    @brief  The function is called when the application enters the foreground
    @param  the pointer of the application instance
    */
    virtual void applicationWillEnterForeground();
};

#endif // _APP_DELEGATE_H_

AppDelegate.cpp

//  Created by HuangYinHui on 11/12/14.
//  Copyright __MyCompanyName__ 2014. All rights reserved.
//

#include "AppDelegate.h"

#include "GameUtils/GameConfig.h"

#include "GameScene/LoadingScene.h"
//#include "GameScene/MainMenuScene.h"
//#include "GameScene/ScratchCardsScene.h"
//#include "GameScene/DialogBoxScene.h"
//#include "GameScene/BuyCoinsScene.h"
#include "GameScene/GameScene.h"
//#include "GameScene/HowToPlayScene.h"
//#include "GameScene/GameEndScene.h"

USING_NS_CC;
using namespace CocosDenshion;

AppDelegate::AppDelegate()
{

}

AppDelegate::~AppDelegate()
{
}

bool AppDelegate::applicationDidFinishLaunching()
{
    // initialize director
    CCDirector *pDirector = CCDirector::sharedDirector();
    pDirector->setOpenGLView(CCEGLView::sharedOpenGLView());

    // turn on display FPS
    pDirector->setDisplayStats(false);

    // set FPS. the default value is 1.0/60 if you don't call this
    pDirector->setAnimationInterval(1.0 / 60);

    loadGameInfo();
    // create a scene. it's an autorelease object
    CCScene *pScene = LoadingScene::scene();
//    CCScene *pScene = MainMenuScene::scene();
//    CCScene *pScene = ScratchCardsScene::scene();
//    CCScene *pScene = DialogBoxScene::scene();
//    CCScene *pScene = BuyCoinsScene::scene();
//    CCScene *pScene = GameScene::scene();
//    CCScene *pScene = HowToPlayScene::scene();
//    CCScene *pScene = GameEndScene::scene();

    // run
    pDirector->runWithScene(pScene);

    return true;
}

// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
void AppDelegate::applicationDidEnterBackground()
{
//    CCNotificationCenter::sharedNotificationCenter()->postNotification(EVENT_COME_TO_BACKGROUND, NULL);
    CCDirector::sharedDirector()->stopAnimation();
    SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
    SimpleAudioEngine::sharedEngine()->pauseAllEffects();
}

// this function will be called when the app is active again
void AppDelegate::applicationWillEnterForeground()
{
    CCDirector::sharedDirector()->startAnimation();
    SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
    SimpleAudioEngine::sharedEngine()->resumeAllEffects();

#if (CC_TARGET_PLATFORM==CC_PLATFORM_ANDROID)
    if (g_pGameScene)
        g_pGameScene->listenToForeground(NULL);
#endif
}

0 个答案:

没有答案