【问题标题】:while running app from xcode push notification is working but when install ipa it is not working从 xcode 推送通知运行应用程序时正在运行,但是在安装 ipa 时它不起作用
【发布时间】:2015-03-07 11:50:55
【问题描述】:

我正在开发一个带有推送通知的 iOS 应用程序,它在使用设备通过 xcode 运行时工作正常。但我尝试生成 ipa 并安装它不起作用。(从后端服务器发送通知,没有生成设备令牌ipa)。我用来注册推送通知的代码。

if ([application respondsToSelector:@selector(isRegisteredForRemoteNotifications)])
{
    // iOS 8 Notifications
    [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];

    [application registerForRemoteNotifications];
}
else
{
    // iOS < 8 Notifications
    [application registerForRemoteNotificationTypes:
     (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)];
}
   - (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
{


NSString *tokenStr = [[[[deviceToken description]
                        stringByReplacingOccurrencesOfString:@"<" withString:@""]
                       stringByReplacingOccurrencesOfString:@">" withString:@""]
                      stringByReplacingOccurrencesOfString:@" " withString:@""];

NSLog(@"Device Token (raw): %@", deviceToken);
NSLog(@"Device Token (string): %@", tokenStr);

NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];

[userDefaults setObject:tokenStr forKey:@"deviceToken"];
[userDefaults synchronize];

}

- (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error
 {
  [MSTLog printdebug:@"Failed to get token, error: %@", error];

 }

我使用的是 xcode 6.1。

【问题讨论】:

    标签: objective-c ios8 xcode6 apple-push-notifications


    【解决方案1】:

    看两件事:

    • 配置文件不包含生产推送证书(通过 Xcode 运行时使用沙盒证书)

    • 确保调用的是 APNS 产品(即 gateway.push.apple.com 而不是 gateway.sandbox.push.apple.com)

    【讨论】:

      【解决方案2】:

      XCode 7.1 及更高版本如果您选择 Adhoc 部署,则 iPA 已通过分发签名,因此 ipa 安装不会收到通知,而通过 XCode 安装时会收到通知。

      解决方案是在导出时使用 save 进行开发部署 生成的 ipa 将通过沙箱收到有关开发证书和配置的通知

      【讨论】:

        【解决方案3】:

        在生成 ipa 时检查配置文件,并确保您的证书和服务器端的证书匹配。

        您的配置文件应配置为推送通知。检查它here

        【讨论】:

        • 是的,我启用了推送通知
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-10-10
        • 1970-01-01
        • 2020-02-23
        • 1970-01-01
        相关资源
        最近更新 更多