0

To create a GKGameSession I need to pass in the iCloud container name.

+ (void)createSessionInContainer:(NSString *)containerName 
                   withTitle:(NSString *)title 
         maxConnectedPlayers:(NSInteger)maxPlayers 
           completionHandler:(void (^)(GKGameSession *session, NSError *error))completionHandler;

Although I know where to find the container name in xCode by navigating to the Capabilities page, and although I know the default format is iCloud.$(CFBundleIdentifier) I'm confused about how I programmatically find the container name.

I don't see it as an entry in the info.plist file. While I could reconstruct it using the default format, what if I don't use the default container name? Do I really have to #definethe string?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Thunk
  • 4,099
  • 7
  • 28
  • 47
  • Did you ever figure out how to identify which container is the iCloud container? Isn't an iCloud container always the local device container, and the local device container is always either totally on iCloud or none at all on iCloud? – daniel Sep 20 '22 at 03:55

1 Answers1

0

To find the default container's ID programmatically:

#import <CloudKit/CloudKit.h>
CKContainer *defaultContainer = [CKContainer defaultContainer];
NSLog(@"default container ID: %@",defaultContainer.containerIdentifier);
Thunk
  • 4,099
  • 7
  • 28
  • 47