// --------------------------------------------------------------------
UPDATE: I messed up. I left a call directly to openfeint in my AppDelegate->onApplicationWillResignActive which was causing the compiler C++ error.
My Appologies, the singleton does work should anyone be thinking of trying the same thing. Just be sure to include the header in the .m file and not the header file.
// --------------------------------------------------------------------
I'm building an iPhone app, and using the Openfeint SDK/Library/Framework (??) which is written in C++.
I'm wondering, is it possible to write a class to interface with C++ so that I don't have to change my ObjC classes to .mm files.
I've tried creating a singleton, in the hope that I could include it's header in normal .m files, but that doesn't work, I still need to make the file that includes the header .mm
The reason I want to do this (or something like this) is because I've no experience with C++, and changing ObjC to C++ files has been causing errors and warnings.
Here's the singleton I created...
// --------------------------------------------------------------------
// OpenfeintController.h
// --------------------------------------------------------------------
#import <Foundation/Foundation.h>
@interface OpenfeintController : NSObject {
NSString *productKey, *secretKey, *displayName;
}
+(OpenfeintController*)sharedOpenfeintController;
- (void) initializeWithProductKey:(NSString *)pKey andSecretKey:(NSString *)sKey andDisplayName:dName;
- (void) launchOpenFeint;
- (void) submitHighScoreToLeaderboard:(NSString *)leaderboardId;
@end
Implmentation
// --------------------------------------------------------------------
// OpenfeintController.mm
// --------------------------------------------------------------------
#import "OpenfeintController.h"
#import "OpenFeint.h"
static OpenfeintController *singletonOpenfeintController = nil;
@implementation OpenfeintController
+(OpenfeintController*)sharedOpenfeintController {
@synchronized(self) {
if (!singletonOpenfeintController) {
singletonOpenfeintController = [[OpenfeintController alloc] init];
}
}
return singletonOpenfeintController;
}
- (void) initializeWithProductKey:(NSString *)pKey andSecretKey:(NSString *)sKey andDisplayName:dName
{
//[OpenFeint initializeWithProductKey:pKey andSecret:sKey andDisplayName:dName andSettings:nil andDelegates:nil];
}
- (void) launchOpenFeint
{
}
- (void) submitHighScoreToLeaderboard:(NSString *)leaderboardId
{
}
@end