ios的app,有新版本时必须先更新。

现在没时间整理,先把代码贴出来,以后再做详细的思路整理。

1 在AppController.mm的didFinishLaunchingWithOptions方法里面获取本地应用版本信息,保存起来。

 // about App version
    NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];  
    NSString *versionStr = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
    SettingsManager::getInstancePtr()->getShortVersion() = [ versionStr UTF8String ];

2 在加载页面,使用http向服务器版本信息,如果返回的版本信息和在第一步中得到的不一致,进入混编文件。

  这只是一些参数。

 //转到appstore 里面
        std::string t = MessageManage::getInstancePtr()->getStrMessage(String_Alter_Version_Title);
        std::string c = MessageManage::getInstancePtr()->getStrMessage(String_Alter_Version_Content);
        std::string b = MessageManage::getInstancePtr()->getStrMessage(String_Alter_Version_Btn);
        ICheckVersionHelper::getInstancePtr()->alertView(t,c,b);

3 我把具体的类都贴上来,包括

ICheckVersionHelper.h  ICheckVersionHelper.app

CheckVersionHelperWin32.h CheckVersionHelperWin32.app 

CheckVersionHelperIOS.mm CheckVersionHelperIOS.h

ICheckVersionHelper.h

#ifndef __ICheckVersionHelper_H__
#define __ICheckVersionHelper_H__

#include "cocos2d.h"
class ICheckVersionHelper
{
public:
    ICheckVersionHelper();

    virtual ~ICheckVersionHelper();

    static ICheckVersionHelper * getInstancePtr();

    virtual void alertView(std::string titlestr,std::string contentstr,std::string btnstr) {}

};


#endif// #ifndef __ICheckVersionHelper_H__

ICheckVersionHelper.app

#include "PrecompiledHeader.h"
#include "ICheckVersionHelper.h"


ICheckVersionHelper::ICheckVersionHelper()
{
}


ICheckVersionHelper::~ICheckVersionHelper()
{
}

CheckVersionHelperWin32.h

#ifndef __CheckVersionHelperWin32_H__
#define __CheckVersionHelperWin32_H__


#include "ICheckVersionHelper.h"


class CheckVersionHelperWin32 : public ICheckVersionHelper
{
public:
    CheckVersionHelperWin32();

    ~CheckVersionHelperWin32();

    static CheckVersionHelperWin32 * getInstancePtr();

private:
    static CheckVersionHelperWin32    m_Singleton;

};


#endif// #ifndef __CheckVersionHelperWin32_H__

CheckVersionHelperWin32.app 

#include "PrecompiledHeader.h"
#include "CheckVersionHelperWin32.h"


CheckVersionHelperWin32 CheckVersionHelperWin32::m_Singleton;


ICheckVersionHelper * ICheckVersionHelper::getInstancePtr()
{
    return ( CheckVersionHelperWin32::getInstancePtr() );
}


CheckVersionHelperWin32::CheckVersionHelperWin32()
{
}


CheckVersionHelperWin32::~CheckVersionHelperWin32()
{
}


CheckVersionHelperWin32 * CheckVersionHelperWin32::getInstancePtr()
{
    return ( &m_Singleton );
}

CheckVersionHelperIOS.h

#ifndef __CheckVersionHelperIOS_H__
#define __CheckVersionHelperIOS_H__


#include "ICheckVersionHelper.h"
#import <UIKit/UIKit.h>

@interface CheckVersionHelper : UIViewController<UIAlertViewDelegate> {
}
@property (nonatomic,retain) NSString *mytitle;
@property (nonatomic,retain) NSString *mycontent;
@property (nonatomic,retain) NSString *mybtn;
- (void) showMyView;
@end


class CheckVersionHelperIOS : public ICheckVersionHelper
{   
public:
    void alertView(std::string titlestr,std::string contentstr,std::string btnstr) override;
    
    static CheckVersionHelperIOS * getInstancePtr();
    
protected:
    CheckVersionHelperIOS() {}
    
    ~CheckVersionHelperIOS() {}
    
private:
    static CheckVersionHelperIOS m_Singleton;

};


#endif

CheckVersionHelperIOS.mm 里面的apple id 我瞎写的。

#include "CheckVersionHelperIOS.h"

@implementation CheckVersionHelper

- (id) init
{
    return self;
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == [alertView cancelButtonIndex]) {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"itms-apps://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=7100000"]];
    }
}
- (void)showMyView
{
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil
                                                   message:self.mycontent
                                                  delegate:self
                                         cancelButtonTitle:self.mybtn
                                         otherButtonTitles:nil,nil];
    [alert show];
    [alert release];
}
@end


ICheckVersionHelper * ICheckVersionHelper::getInstancePtr()
{
    return ( CheckVersionHelperIOS::getInstancePtr() );
}

CheckVersionHelperIOS CheckVersionHelperIOS::m_Singleton;

CheckVersionHelperIOS * CheckVersionHelperIOS::getInstancePtr()
{
    return ( &m_Singleton );
}
void CheckVersionHelperIOS::alertView(std::string titlestr,std::string contentstr,std::string btnstr)
{
    CheckVersionHelper * myhelper = [[CheckVersionHelper alloc] init];
    [myhelper setMytitle:[NSString stringWithUTF8String:titlestr.c_str()]];
    [myhelper setMycontent:[NSString stringWithUTF8String:contentstr.c_str()]];
    [myhelper setMybtn:[NSString stringWithUTF8String:btnstr.c_str()]];
    [myhelper showMyView ];
}

 

 

 

 

 

 

 

 

 

posted @ 2013-10-22 12:19  彼岸Elan  阅读(6250)  评论(0编辑  收藏  举报