https://github.com/googlesamples/google-services/blob/master/ios/gcm/GcmExample/
,
( [[GGLInstanceID sharedInstance] tokenWithAuthorizedEntity
, ),
[[GGLInstanceID sharedInstance] startWithConfig:
[[GCMService sharedInstance] connectWithHandler:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSError* configureError;
[[GGLContext sharedInstance] configureWithError:&configureError];
if (configureError) {
NSLog(@"Error configuring Google services: %@", configureError);
}
GCMConfig *gcmConfig = [GCMConfig defaultConfig];
gcmConfig.receiverDelegate = self;
[[GCMService sharedInstance] startWithConfig:gcmConfig];
{
GGLInstanceIDConfig *instanceIDConfig = [GGLInstanceIDConfig defaultConfig];
instanceIDConfig.delegate = self;
[[GGLInstanceID sharedInstance] startWithConfig:instanceIDConfig];
}
...
[self requestAndSynchronizeGCMTokenIfNeeded];
...
return YES;
}
, , [[GGLInstanceID sharedInstance] tokenWithAuthorizedEntity:
, chcek applicationDidBecomeActive
smth.
- (void)applicationDidBecomeActive:(UIApplication *)application {
if (self.data.deviceToken) {
[[GCMService sharedInstance] connectWithHandler:^(NSError *error) {
if (error) {
NSLog(@"Could not connect to GCM: %@", error.localizedDescription);
} else {
self.connectedToGCM = YES;
NSLog(@"Connected to GCM");
[self subscribeToTopic];
}
}];
}
}
, tokenWithAuthorizedEntity:
, , , ,
[[GGLInstanceID sharedInstance] tokenWithAuthorizedEntity:gcmSenderID scope:kGGLInstanceIDScopeGCM options:options handler:^(NSString *token, NSError *error) {
// connect to GCM also here ([[GCMService sharedInstance] connectWithHandler:)
}