警告XCodeGLKit已被废弃,请考虑迁移到Metal,并通过Apple电子邮件发送废弃的API用法,使用WKWebView代替UIWebView。

问题描述 投票:-1回答:1

我已经使用Buildbox 2.3.3完成了我的游戏,并且已经在Xcode上清理了尽可能多的警告。然而,我已经在这个我从OpenGL迁移到Metal上几个星期了,我认为这是我在Xcode中出现那个错误的原因,说GLKit被废弃了,考虑迁移到金属,而不是。

我尝试将游戏上传到App store connect,没有我解决这个错误,但是我马上收到一封邮件说

ITMS-90809: 废弃的API用法,新应用不再使用UIWebView,改用WKWebView。

我不知道如何去转换我的代码,以迎合这一点,我真的很感激一些指导,或者如果有人能为我重写我的代码,将OpenGL转换为金属。

我把我使用的代码附在下面,如果有人能帮助我,我会非常感激。我已经在这个最后阶段卡了好几周了,非常沮丧。

AppDelegate.h

#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>{
}

@property (strong, nonatomic) UIWindow *window;


@end

AppDelegate.mm

#import "AppDelegate.h"
#import <GLKit/GLKit.h>
#include "PTPSettingsController.h"
#include "libs/cocos2dx/include/audio/include/SimpleAudioEngine.h"

@interface AppDelegate ()

@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    return YES;
}


- (void)applicationWillResignActive:(UIApplication *)application {
    cocos2d::CCDirector::sharedDirector()->pause();
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    cocos2d::CCApplication::sharedApplication()->applicationDidEnterBackground();
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    cocos2d::CCApplication::sharedApplication()->applicationWillEnterForeground();
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    cocos2d::CCDirector::sharedDirector()->resume();
}

- (void)applicationWillTerminate:(UIApplication *)application {
}

- (void)loadingDidComplete{
}

-(void)showCustomFullscreenAd{
}

- (void)screenOnEnter:(const char*) name{
}

- (void)screenOnExit:(const char*) name{
}

@end

游戏ViewController.h

#import <UIKit/UIKit.h>
#import <GLKit/GLKit.h>

@interface GameViewController : GLKViewController

@end

游戏视图控制器.mm

#import "GameViewController.h"
#import <OpenGLES/ES2/glext.h>
#import "PTModelController.h"
#import "PTModelGeneralSettings.h"
#import "PTPAppDelegate.h"
#import "cocos2d.h"
#import "PTPConfig.h"
#include "PTPSettingsController.h"


#define IOS_MAX_TOUCHES_COUNT     10

static PTPAppDelegate s_sharedApplication;

@interface GameViewController () {
    NSString* shareMessage;
    bool sheduledForShareWidget;
}
@property (strong, nonatomic) EAGLContext *context;

@end

@implementation GameViewController

- (void)viewDidLoad{
    [super viewDidLoad];

    sheduledForShareWidget = false;
    self.context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];

    if (!self.context) {
        NSLog(@"Failed to create ES context");
    }

    GLKView *view = (GLKView *)self.view;
    view.context = self.context;
    view.drawableDepthFormat = GLKViewDrawableDepthFormat24;
    [view setMultipleTouchEnabled: YES];

    [self setPreferredFramesPerSecond:60];
    [EAGLContext setCurrentContext:self.context];

    PTModelController *mc = PTModelController::shared();
    mc->clean();

    unsigned long size = 0;
    char* pBuffer = (char*)CCFileUtils::sharedFileUtils()->getFileData("data/data.pkg", "rb", &size);
    if (pBuffer != NULL && size > 0){
        mc->setUsingDataEncryption( true );
    }

    mc->loadDataForSplashScreen("data/data.pkg", processor().c_str());

    s_sharedApplication.setDataArchiveProcessor(processor());


    cocos2d::CCApplication::sharedApplication()->run();
}

- (void)dealloc{
    if ([EAGLContext currentContext] == self.context) {
        [EAGLContext setCurrentContext:nil];
    }
}

- (void)didReceiveMemoryWarning{
    [super didReceiveMemoryWarning];

    if ([self isViewLoaded] && ([[self view] window] == nil)) {
        self.view = nil;

        if ([EAGLContext currentContext] == self.context) {
            [EAGLContext setCurrentContext:nil];
        }
        self.context = nil;
    }

    // Dispose of any resources that can be recreated.
}

- (BOOL)prefersStatusBarHidden {
    return YES;
}

- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect{
    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    cocos2d::CCDirector::sharedDirector()->setViewport();
    cocos2d::CCDirector::sharedDirector()->mainLoop();
}


- (void)update{
    if(sheduledForShareWidget == true){
        sheduledForShareWidget = false;

        GLKView *view  = (GLKView *)self.view;
        UIImage* screenshot = view.snapshot;

        PTLog("Opens Share Widget: screenshot was taken");

        UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:@[shareMessage, screenshot] applicationActivities:nil];

        NSArray *excludeActivities = @[UIActivityTypeSaveToCameraRoll,
                                       UIActivityTypeAssignToContact];
        activityVC.excludedActivityTypes = excludeActivities;


        float iOSVersion = [[UIDevice currentDevice].systemVersion floatValue];
        if(iOSVersion > 8.0){
            activityVC.popoverPresentationController.sourceView = self.view;
        }

        [self presentViewController:activityVC animated:YES completion:nil];
        PTLog("opens Share Widget: view controller presented");
    }
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event{
    int ids[IOS_MAX_TOUCHES_COUNT] = {0};
    float xs[IOS_MAX_TOUCHES_COUNT] = {0.0f};
    float ys[IOS_MAX_TOUCHES_COUNT] = {0.0f};

    int i = 0;
    for (UITouch *touch in touches) {
        ids[i] = (intptr_t)touch;
        xs[i] = [touch locationInView: [touch view]].x * self.view.contentScaleFactor;
        ys[i] = [touch locationInView: [touch view]].y * self.view.contentScaleFactor;
        ++i;
    }
    cocos2d::CCEGLView::sharedOpenGLView()->handleTouchesBegin(i, ids, xs, ys);
}

- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event{
    int ids[IOS_MAX_TOUCHES_COUNT] = {0};
    float xs[IOS_MAX_TOUCHES_COUNT] = {0.0f};
    float ys[IOS_MAX_TOUCHES_COUNT] = {0.0f};

    int i = 0;
    for (UITouch *touch in touches) {
        ids[i] = (intptr_t)touch;
        xs[i] = [touch locationInView: [touch view]].x * self.view.contentScaleFactor;;
        ys[i] = [touch locationInView: [touch view]].y * self.view.contentScaleFactor;;
        ++i;
    }
    cocos2d::CCEGLView::sharedOpenGLView()->handleTouchesMove(i, ids, xs, ys);
}

- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event{
    int ids[IOS_MAX_TOUCHES_COUNT] = {0};
    float xs[IOS_MAX_TOUCHES_COUNT] = {0.0f};
    float ys[IOS_MAX_TOUCHES_COUNT] = {0.0f};

    int i = 0;
    for (UITouch *touch in touches) {
        ids[i] = (intptr_t)touch;
        xs[i] = [touch locationInView: [touch view]].x * self.view.contentScaleFactor;;
        ys[i] = [touch locationInView: [touch view]].y * self.view.contentScaleFactor;;
        ++i;
    }
    cocos2d::CCEGLView::sharedOpenGLView()->handleTouchesEnd(i, ids, xs, ys);
}

- (void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event{
    int ids[IOS_MAX_TOUCHES_COUNT] = {0};
    float xs[IOS_MAX_TOUCHES_COUNT] = {0.0f};
    float ys[IOS_MAX_TOUCHES_COUNT] = {0.0f};

    int i = 0;
    for (UITouch *touch in touches) {
        ids[i] = (intptr_t)touch;
        xs[i] = [touch locationInView: [touch view]].x * self.view.contentScaleFactor;;
        ys[i] = [touch locationInView: [touch view]].y * self.view.contentScaleFactor;;
        ++i;
    }
    cocos2d::CCEGLView::sharedOpenGLView()->handleTouchesCancel(i, ids, xs, ys);
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    PTModelGeneralSettingsPtr generalSettings = PTModelGeneralSettings::shared();
    if(generalSettings->orientation() == PTModelGeneralSettings::LandscapeOrientation){
        return UIInterfaceOrientationIsLandscape( interfaceOrientation );
    }
    else if(generalSettings->orientation() == PTModelGeneralSettings::PortraitOrientation){
        return UIInterfaceOrientationIsPortrait( interfaceOrientation );
    }

    return NO;
}

- (NSUInteger) supportedInterfaceOrientations{
    PTModelGeneralSettingsPtr generalSettings = PTModelGeneralSettings::shared();
    if(generalSettings->orientation() == PTModelGeneralSettings::LandscapeOrientation){
        return UIInterfaceOrientationMaskLandscape;

    }
    else if(generalSettings->orientation() == PTModelGeneralSettings::PortraitOrientation){
        return UIInterfaceOrientationMaskPortrait;
    }

    return NO;
}

- (BOOL) shouldAutorotate {
    return NO;
}

-(void) scheduleOpenShareWidget:(const char*) message{
    shareMessage = [NSString stringWithUTF8String:message];
    sheduledForShareWidget = true;
}

@end
xcode opengl metal glkit buildbox
1个回答
0
投票

已经告诉你了,你的问题有点不适合在Stack Overflow上讨论。你可以从以下几点开始重写你的项目 OpenGL金属如果有任何问题,请提出问题。

苹果的文档是一个很好的起点。

你也可以观看 WWDC 2019视频 并学习将基于OpenGL的应用程序过渡到Metal API的逐步方法。

© www.soinside.com 2019 - 2024. All rights reserved.