2016-07-14 13 views
-1

ich nicht jede Art von pod (nicht Kakaoschote verwenden)Selbst presentViewController: Viewcontroller animiert: JA nicht funktioniert

Ich habe meine gesetzt AppController wie unten:

@interface AppController : UIViewController <UIApplicationDelegate, GIDSignInDelegate , GIDSignInUIDelegate> 
(die mein viewController ist)

dann, wenn ich genannt: [[GIDSignIn sharedInstance] signIn]; dann:

[self presentViewController:viewController animated:YES completion:nil]; 

Problem schaffen und zeigen Sie mir den Fehler:

whose view is not in the window hierarchy!

Oder wenn ich UIViewController entfernen und ersetzen Sie es zu UIResponder dann Fehler:

UIDelegate must either be a |UIViewController| or implement the |signIn:presentViewController:| and |signIn:dismissViewController:| methods from |GIDSignInUIDelegate|

ich möchte nur ein google sign-in UI zeigen:

Was fehlt mir? Bin ich falsch mit Controllern? Ich brauche wirklich Hilfe hier. Mein Ziel c ist fast vernachlässigbar. Ich habe keinen Code gefunden cocos2dx und google sign-in. Dort gibt es nur schnelle Codes.

Hier ist mein Code, wo ich Fehler mache:

AppController.h Datei Code.

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

#import <GoogleSignIn/GoogleSignIn.h> 
#import <GoogleSignIn/GIDAuthentication.h> 
#import <GoogleSignIn/GIDGoogleUser.h> 
#import <GoogleSignIn/GIDProfileData.h> 
#import <GoogleSignIn/GIDSignInButton.h> 
#import <GoogleSignIn/GoogleSignIn.h> 

@class RootViewController; 


@interface AppController : UIViewController <UIApplicationDelegate, GIDSignInDelegate , GIDSignInUIDelegate> { 
    UIWindow *window; 
    RootViewController* viewController; 
} 

@property(nonatomic, retain) UIWindow *window; 
@property(nonatomic, readonly) RootViewController* viewController; 

@end 

AppController.mm Dateicode.

//------------------------------------------------- 
// AppController.mm 


#import "AppController.h" 
#import "platform/ios/CCEAGLView-ios.h" 
#import "cocos2d.h" 
#import "AppDelegate.h" 
#import "RootViewController.h" 
#import "HelloWorld_ios.h" 


//#import <GoogleSignIn/G> 

@implementation AppController 


static NSString * const kClientID [email protected]"884216498839-g2j0jlq70k249m2ri3lchp4bq1sf1qmb.apps.googleusercontent.com"; 

#pragma mark - 
#pragma mark Application lifecycle 

// cocos2d application instance 
static AppDelegate s_sharedApplication; 

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

    [GIDSignIn sharedInstance].delegate = self; 
    [GIDSignIn sharedInstance].uiDelegate = self; 
    [GIDSignIn sharedInstance].clientID = kClientID; 
    [GIDSignIn sharedInstance].shouldFetchBasicProfile = YES; 

    cocos2d::Application *app = cocos2d::Application::getInstance(); 
    app->initGLContextAttrs(); 
    cocos2d::GLViewImpl::convertAttrs(); 

    window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]]; 

    CCEAGLView *eaglView = [CCEAGLView viewWithFrame: [window bounds] 
             pixelFormat: (NSString*)cocos2d::GLViewImpl::_pixelFormat 
             depthFormat: cocos2d::GLViewImpl::_depthFormat 
            preserveBackbuffer: NO 
              sharegroup: nil 
             multiSampling: NO 
            numberOfSamples: 0 ]; 

    [eaglView setMultipleTouchEnabled:NO]; 

    _viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil]; 
    _viewController.wantsFullScreenLayout = YES; 
    _viewController.view = eaglView; 

    // Set RootViewController to window 
    if ([[UIDevice currentDevice].systemVersion floatValue] < 6.0) 
    { 
     // warning: addSubView doesn't work on iOS6 
     [window addSubview: _viewController.view]; 
    } 
    else 
    { 
     // use this method on ios6 
     [window setRootViewController:_viewController]; 
    } 

    [window makeKeyAndVisible]; 

    [[UIApplication sharedApplication] setStatusBarHidden:true]; 

    // IMPORTANT: Setting the GLView should be done after creating the RootViewController 
    cocos2d::GLView *glview = cocos2d::GLViewImpl::createWithEAGLView(eaglView); 
    cocos2d::Director::getInstance()->setOpenGLView(glview); 

    app->run(); 

    [[GIDSignIn sharedInstance] signInSilently]; 

    return YES; 
} 


- (BOOL)application:(UIApplication *)app 
      openURL:(NSURL *)url 
      options:(NSDictionary *)options { 

    return [[GIDSignIn sharedInstance] handleURL:url 
           sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey] 
             annotation:options[UIApplicationOpenURLOptionsAnnotationKey]]; 
} 

// For ios 8 .... 

- (BOOL)application:(UIApplication *)application 
      openURL:(NSURL *)url 
    sourceApplication:(NSString *)sourceApplication 
     annotation:(id)annotation { 

    return [[GIDSignIn sharedInstance] handleURL:url 
           sourceApplication:sourceApplication 
             annotation:annotation]; 
} 



- (void)signIn:(GIDSignIn *)signIn 
didSignInForUser:(GIDGoogleUser *)user 
    withError:(NSError *)error { 
} 

- (void)signInWillDispatch:(GIDSignIn *)signIn error:(NSError *)error { 

} 

- (void)signIn:(GIDSignIn *)signIn presentViewController:(UIViewController *)viewController 
{ 
    [self presentViewController:viewController animated:YES completion:nil]; 
} 

// Dismiss the "Sign in with Google" view 
- (void)signIn:(GIDSignIn *)signIn 
dismissViewController:(UIViewController *)viewController { 

    [self dismissViewControllerAnimated:YES completion:nil]; 

} 





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

} 

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

} 

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


    cocos2d::Application::getInstance()->applicationDidEnterBackground(); 
} 

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

    cocos2d::Application::getInstance()->applicationWillEnterForeground(); 
} 

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

} 


#pragma mark - 
#pragma mark Memory management 

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

} 


- (void)dealloc { 
    [window release]; 
    [super dealloc]; 
} 


@end 

Datei HelloWorld_ios.h.

// ============================================= 
// HelloWorld_ios.h 

#import <Foundation/Foundation.h> 
#import <UIKit/UIKit.h> 
#import <GoogleSignIn/GoogleSignIn.h> 
#import <GoogleSignIn/GIDAuthentication.h> 
#import <GoogleSignIn/GIDGoogleUser.h> 
#import <GoogleSignIn/GIDProfileData.h> 
#import <GoogleSignIn/GIDSignInButton.h> 
#import <GoogleSignIn/GoogleSignIn.h> 
#include "AppController.h" 

@interface HelloWorld_ios : UIViewController <GIDSignInUIDelegate, GIDSignInDelegate,UIAlertViewDelegate> 
{//@interface HelloWorld_ios 


} 

- (void)initialize; 

@end 

HelloWorld_ios.mm Code ist hier, wo signin gedrückt auf Taste ruft.

// ============================================= 
// HelloWorld_ios.mm 


#import "AppController.h" 
#import "AppDelegate.h" 
#import "HelloWorld_ios.h" 
#import "../../proj.ios_mac/ios/AppController.h" 

#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) 
#ifdef __OBJC__ 
#import "IOSNDKHelper.h" 
#endif 
#endif 

@implementation HelloWorld_ios 

//C++ Call via NDK 
- (void)initialize 
{ 
    [IOSNDKHelper addNDKReceiver:self moduleName:@"receiver_LocalNotifications"]; 
    CCLOG("test5 in the intiallize()...ios..."); 


} 

- (void) CallingForSignIn:(NSObject*) params 
{ 
    NSMutableDictionary *mapData = (NSMutableDictionary*) params; 
    NSString* receiveData = [mapData objectForKey:@"testData"]; 
    NSLog(@"This is test1 NDK %@",receiveData); 

// [[GIDSignIn sharedInstance] signOut]; 
// [[GIDSignIn sharedInstance] signInSilently]; 
    [[GIDSignIn sharedInstance] signIn]; 

} 


- (void) CallingForSignOut:(NSObject*) params 
{ 
    NSMutableDictionary *mapData = (NSMutableDictionary*) params; 
    NSString* receiveData = [mapData objectForKey:@"testData"]; 
    NSLog(@"This is test1 NDK %@",receiveData); 

    [[GIDSignIn sharedInstance] signOut]; 

} 


@end 
+0

Ich möchte mehr Code und Ihre Erklärungen sehen – Happiehappie

Antwort

0

"deren Ansicht nicht in der Fensterhierarchie ist!" Ausgabe fast fällig wegen:

Sie haben View-Controller (und noch nicht vorgestellt) und versuchen, eine andere Ansicht darüber zu präsentieren.

+0

Ich habe meinen Code hier hinzugefügt, möglicherweise können Sie die Antwort identifizieren. –

0

Haben Sie zum rootviewcontroller hinzugefügt? Die Fehlermeldung beschweren es deutlich.

+0

Ich habe meinen Code dort hinzugefügt, Sie können sehen, was darin falsch ist. –

Verwandte Themen