2015-10-27 10 views
0

Привет я хочу реализовать GCM в прошивкой и у меня есть мой SenderID но я не знаю, где я должен реализовать SenderId .Это весь мой код для GCM integration.i нужно лексема value.so, пожалуйста, помогите мне сделать это.Google Cloud Messaging в прошивкой

AppDelegate:

#import "AppDelegate.h" 

@interface AppDelegate() 
{ 
    NSDictionary *RegistrationOptions; 
    NSString *GcmSenderID; 
    GGLInstanceIDTokenHandler registrationHandler; 
} 
@end 

@implementation AppDelegate 


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

    // Override point for customization after application launch. 
    UIUserNotificationType allNotificationTypes=(UIUserNotificationTypeSound|UIUserNotificationTypeBadge); 
    UIUserNotificationSettings *settings=[UIUserNotificationSettings settingsForTypes:allNotificationTypes categories:nil]; 
    [[UIApplication sharedApplication]registerUserNotificationSettings:settings]; 
    [[UIApplication sharedApplication]registerForRemoteNotifications]; 

    return YES; 
} 
-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{ 

    // Create a config and set a delegate that implements the GGLInstaceIDDelegate protocol. 
    GGLInstanceIDConfig *instanceIDConfig = [GGLInstanceIDConfig defaultConfig]; 
    instanceIDConfig.delegate = self; 
    // Start the GGLInstanceID shared instance with the that config and request a registration 
    // token to enable reception of notifications 
    [[GGLInstanceID sharedInstance] startWithConfig:instanceIDConfig]; 
    RegistrationOptions = @{kGGLInstanceIDRegisterAPNSOption:deviceToken, 
          kGGLInstanceIDAPNSServerTypeSandboxOption:@YES}; 
    [[GGLInstanceID sharedInstance] tokenWithAuthorizedEntity:GcmSenderID 
                 scope:kGGLInstanceIDScopeGCM 
                 options:RegistrationOptions 
                 handler:registrationHandler]; 

} 

- (void)onTokenRefresh { 
    // A rotation of the registration tokens is happening, so the app needs to request a new token. 
    NSLog(@"The GCM registration token needs to be changed."); 
    [[GGLInstanceID sharedInstance] tokenWithAuthorizedEntity:GcmSenderID 
                 scope:kGGLInstanceIDScopeGCM 
                 options:RegistrationOptions 
                 handler:registrationHandler]; 


} 
+0

, пожалуйста, дайте мне знать ответ – Arun

ответ

0

Его довольно поздно answer.But это поможет кому-то в будущем.

Вам нужно загрузить apns certificate (разработчик и производство) и получить файл gcm config и добавить его в свой проект (перетащить его в проект).

Следующий код, который вы должны позвонить в didFinishLaunchingWithOptions, автоматически выберет _gcmSenderID из конфигурационного файла.

_gcmSenderID = [[[GGLContext sharedInstance] configuration] gcmSenderID];

Вотsample quick start projectдля вас, чтобы начать с. (Как быстрой и Objective-C) .Everything хорошо объясняется в этом образце app.Let мне знать, если у вас есть какие-либо сомнения.

Смежные вопросы