ios - GCM 似乎没有向 iOS 存档应用程序注册

标签 ios iphone google-cloud-messaging cocoapods

我已按照 google 说明将 GCM 实现到我的 iOS 项目中。直接在我的设备上运行应用程序时,一切正常,但如果我存档应用程序并通过本地 iTunes 安装它,那么 GCM 似乎未注册,并且我没有收到 token 。我很挣扎,因为我无法调试存档的应用程序,所以我发现很难找出问题所在。

我不确定这是 cocoapods 问题还是某种库问题,甚至是签名问题。

有人对我如何调试它有什么建议吗?我假设我的应用程序的存档版本仍将运行与直接在我的设备上运行相同的调试版本,我认为唯一不同的是当您存档为 AdHoc 时完成的签名。

更新

 - (BOOL)application:(UIApplication *)application       didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
 {
[self setRootViewControllerByCheckingLoginStatus];
// [START register_for_remote_notifications]
// [START_EXCLUDE]
_registrationKey = @"onRegistrationCompleted";
_messageKey = @"onMessageReceived";
// Configure the Google context: parses the GoogleService-Info.plist, and initializes
// the services that have entries in the file
NSError* configureError;
[[GGLContext sharedInstance] configureWithError:&configureError];
if (configureError != nil) {
    NSLog(@"Error configuring the Google context: %@", configureError);
}
_gcmSenderID = [[[GGLContext sharedInstance] configuration] gcmSenderID];
// [END_EXCLUDE]
// Register for remote notifications
UIUserNotificationType allNotificationTypes =
(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge);
UIUserNotificationSettings *settings =
[UIUserNotificationSettings settingsForTypes:allNotificationTypes categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
[[UIApplication sharedApplication] registerForRemoteNotifications];
// [END register_for_remote_notifications]
// [START start_gcm_service]
[[GCMService sharedInstance] startWithConfig:[GCMConfig defaultConfig]];
// [END start_gcm_service]
__weak typeof(self) weakSelf = self;
// Handler for registration token request
_registrationHandler = ^(NSString *registrationToken, NSError *error){
    if (registrationToken != nil)
    {
        NSString *regID = registrationToken;

        [[NSUserDefaults standardUserDefaults] setObject: regID forKey:@"regID"];
        [[NSUserDefaults standardUserDefaults]synchronize];
        weakSelf.registrationToken = registrationToken;
        NSLog(@"Registration Token: %@", registrationToken);
        [weakSelf subscribeToTopic];
        NSDictionary *userInfo = @{@"registrationToken":registrationToken};
        [[NSNotificationCenter defaultCenter] postNotificationName:weakSelf.registrationKey
                                                            object:nil
                                                          userInfo:userInfo];
                    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Success"
                                                            message:registrationToken
                                                           delegate:nil
                                                  cancelButtonTitle:@"Ok"
                                                  otherButtonTitles:nil, nil];
        [alertView show];
    }
    else
    {
        NSLog(@"Registration to GCM failed with error: %@", error.localizedDescription);
        NSDictionary *userInfo = @{@"error":error.localizedDescription};
        [[NSNotificationCenter defaultCenter] postNotificationName:weakSelf.registrationKey
                                                            object:nil
                                                          userInfo:userInfo];
    }
};
return YES;

最佳答案

我设法通过将控制台日志发送到文件然后将文件读入 TextView 来解决此问题。我收到的错误是“在应用商店中找不到应用程序的有效‘aps-environment’授权字符串”

原来是配置文件的问题。由于某种原因,我将它命名为与我的包 ID 相同的名称,我不完全确定这是否是问题所在,但是当我创建一个新包时它运行良好

关于ios - GCM 似乎没有向 iOS 存档应用程序注册,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32457732/

相关文章:

ios - iphone 7 不支持 css

ios - 将一个 UIView 的约束交换到另一个 UIView

ios - AlamoFire 无线程警告

iOS:无法让蓝牙管理器工作

ios - 如何测试启动 View Controller XCTest

iphone - 手机的当前 IP 地址,无论是通过 WiFi 还是 3G 连接

android - 电话间隙 : "processMessage failed" unable to send javascript function (Cordova 2. 5.0)

ios - IOS平台是否可以在拨出或来电时显示图片或视频?

android - GCM的不同口味

android - GCM http 401 授权错误