Skip navigation

Tag Archives: ios

There is a really shitty post on stackoverflow about this, filled with nonsense.

I’m working with old OpenGL code. Specifically, code based off GLES2Sample.

There was a slight change around iOS 5.0 or so, requiring you to have a root view controller. If your code is based off older sample code, such as GLES2Sample, then no root view controller was created in those code samples.

To fix GLES2Sample, I know the following fix works. Right in `applicationDidFinishLaunching`, I create a root view controller and attach my glView to it.

    - (void) applicationDidFinishLaunching:(UIApplication *)application
    {
      // To make the 'Application windows are expected
      // to have a root view controller
      // at the end of application launch' warning go away,
      // you should have a rootviewcontroller,
      // but this app doesn't have one at all.
      window.rootViewController = [[UIViewController alloc] init];  // MAKE ONE
      window.rootViewController.view = glView; // MUST SET THIS UP OTHERWISE
      // THE ROOTVIEWCONTROLLER SEEMS TO INTERCEPT TOUCH EVENTS
    }

That makes the warning go away, and doesn’t really affect your app otherwise.

GameCenter isn’t easy to work with. For one it’s networking, and networking errors are hard to debug because there’s no natural UI. debug print messages is all you’ve got. It doesn’t help that GC is none too detailed on what you did wrong, and sometimes weird errors can occur if you use the API incorrectly.

1. A match request by name can take up to 2 minutes to reach the remote device. Unprepared for this I’d just sit there trying the request again and again, wondering why it wasn’t working.

2. The iOS simulator doesn’t seem to work for GKMatchmaker requests. I don’t know why this is, but the iOS simulator cannot even startBrowsingForNearbyPlayersWithReachableHandler.

3.

I can never find this when I’m looking for it, so I dedicated a whole blog post to it.

Here.

Delegate: A person sent or authorized to represent others
Delegation

First, DELEGATE is problematic. It’s not a common word, and most people don’t know what it means, and beyond that it’s NOT CLEAR what it means in a software context. It’s a bad metaphor.

The use of the word DELEGATE is different than in C#. A delegate in C# is just a function pointer. A DELEGATE in Objective-C is an OBJECT that implements a bunch of functions (very similar to overriding methods in inheritance), BUT THESE FUNCTIONS AREN’T OVERRIDING FUNCTIONS IN A BASE CLASS. Instead, they are implementing A “PROTOCOL” (not a C++ programming concept, its an objective-c concept). OC PROTOCOLS are like C++ INTERFACES (abstract base classes), only weirder. Delegate classes contain just a bunch of stubs of functionality that would get called by the default Apple UIApplication object, if that object respondsToSelector, for example.

Some Foundation Framework classes are like big assholes, like UIApplication for example. They go about their business in a VERY routine way, and WHEN THEY FEEL LIKE IT, they “delegate” little tasks out to YOUR DELEGATE OBJECT. When you program with Foundation classes, you provide that itty-bitty, gopher-boy, go-do-what-I-said, shoe-shine, lackey-boy, I-have-no-money-please-help-me-sir object (called a DELEGATE). The big king UIApplication Foundation class WILL CALL YOUR DELEGATE WHEN THE TIME COMES.

So your little shitty delegate just implements willDoStep3 here, and arguments may be passed by Framework object. UIApplication has a bunch of points at which it “needs” a delegate to call: applicationDidFinishLaunching, applicationWillResignActive, etc.

So app delegation is like fake inheritance. In normal inheritance, you would OVERRIDE applicationDidFinishLaunching, and provide your own method stub. In Objective C, you “provide a delegate object that implements a protocol”. It is conceptually almost the same thing.

I don’t understand why Apple decided to invent this new language and concepts of protocols and delegates, when C++’s concepts of interfaces and inheritance do just fine.


As an example of implementing a delegate protocol, let’s implement GKMatchDelegate. All the information you need is in the documentation there.

// SFMatchDelegate : inherits from NSObject< Implements GKMatchDelegate protocol >
@interface SFMatchDelegate : NSObject< GKMatchDelegate >
{
}

// any @property here

@end



// Usually in another file:
@implementation SFMatchDelegate

//any @synthesize statements

// "override"/implement protocol "Tasks"

//Receiving Data from Other Players
- (void)match:(GKMatch *)match didReceiveData:(NSData *)data fromPlayer:(NSString *)playerID
{
}

//Receiving State Notifications About Other Players
- (void)match:(GKMatch *)match player:(NSString *)playerID didChangeState:(GKPlayerConnectionState)state
{
}

//Handling Errors
- (void)match:(GKMatch *)match didFailWithError:(NSError *)error
{
}

//Reinviting a Player
- (BOOL)match:(GKMatch *)match shouldReinvitePlayer:(NSString *)playerID
{
  return YES ;
}

@end