1

我已经在应用商店里有一个应用。现在我想添加APNS。在开发者门户上,我设置了开发者证书并为我的应用程序启用了 APNS。我创建了一个新的配置文件并将其设置在我的应用程序中的调试下。我已删除所有其他配置文件。

当我在我的 iphone 上运行我的应用程序时,我发送了 registerForRemoteNotificationTypes 但从未得到苹果的响应,也没有调用错误委托。如果我删除 iPhone 上的应用程序并重新安装,它永远不会询问推送通知。

在过去的两天里,我已经阅读了尽可能多的关于该主题的堆栈溢出文章和教程/Apple 文档,但到目前为止似乎没有任何东西可以解决我的问题。

我检查过的其他事项:
- 检查 Entitlements.plist 文件中是否有坏密钥
- 检查下载的 .mobileprovision 文件中是否有带有开发字符串的 aps-environment
- 删除我的管理器中的所有其他配置文件 -> 设备以及钥匙串
- 更改日期在我的 iPhone 上向前一天,关机,开机,重新加载应用程序

有没有人对尝试什么有任何其他建议,或者为什么尝试在现有应用程序上设置 APNS 似乎不起作用?

请注意,我试图用 APNS 开发一个新版本,而不是问为什么发布的版本还不能工作。一旦我可以使用 APNS 进行调试,我就会选择 disto APNS。提前致谢。

[编辑] 我想你误解了我的问题。我已经阅读了文档并完成了这些步骤。事实上,同样的代码曾经一度有效,我在几个主要版本前暂时禁用了它,但现在想重新启用它。我也看过同样的教程。据我所知,主要问题不是我的代码,它的配置文件或与 Apple 的错误有关的东西,以及它如何处理现有文件或其他东西中的推送证书。

这是我的代码,但正如我所说,我不认为它在这一点上是我的代码,它与配置或其他东西有关。我已经验证我称之为,但在 IOS 开发站点上设置推送证书以及获取新的配置文件后,从未收到任何代表的回调。

[application registerForRemoteNotificationTypes:
     (UIRemoteNotificationType)
     (UIRemoteNotificationTypeBadge |
      UIRemoteNotificationTypeSound |
      UIRemoteNotificationTypeAlert) ];

代表永远不会被召唤:


- (void) application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
    [Log log:TINFO :@"==== APNS didRegisterForRemoteNotifcationsWithDeviceToken ===="];

    NSString *devtok = [NSString stringWithFormat:@"%@",deviceToken];
    devtok = [devtok stringByReplacingOccurrencesOfString: @"" withString: @""];
    devtok = [devtok stringByReplacingOccurrencesOfString: @" " withString: @""];

    NSString *stok = [[[NSString alloc] initWithFormat:@"%@", devtok] autorelease];

    [Log log:TINFO :@"saving ", devtok];

    UpdateDevToken *utok = [[UpdateDevToken alloc] autorelease];
    [utok updateDeviceToken:stok];

}

错误委托:

- (void)application:(UIApplication *)application    didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
    [Log log:TERR :@"==== APNS didFailToRegisterForRemoteNotificationsWithError: %@", error.localizedDescription];
}

[编辑 2] 忘了补充说我也有 didReceiveRemoteNotification:

- (void)application:(UIApplication *)application didReceiveRemoteNotification(NSDictionary *)userInfo
{
[Log log:TENT :@"==== APNS didReceiveRemoteNotification"];
}

我的代表都没有接到电话。

4

1 回答 1

0

首先查看 APNS 上的 Apple 文档。

查看Raywander 教程。

然后修改我们的 AppDelegate 类。

      // Add This to did to 
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        ........
      [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
       return YES;
    }

    - (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
        {
            NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

            if ([defaults valueForKey:@"device_token"]) { // Check existing device token
                NSLog(@"My saved token is: %@", [defaults valueForKey:@"device_token"]);
            }

            NSString *deviceTokenString = [[deviceToken description] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]];
            deviceTokenString = [deviceTokenString stringByReplacingOccurrencesOfString:@" " withString:@""];

            [defaults setObject:deviceTokenString forKey:@"device_token"];
            [defaults synchronize];

            NSLog(@"My token is: %@", deviceTokenString);
        }

        - (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error
        {
            NSLog(@"Failed to get token, error: %@", error);
            //[self showAlertMessage:@"Failed to get token, error!"];

        }
        - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
        {
            NSLog(@"userInfo :%@",userInfo);
            //[self setUser:[[userInfo valueForKey:@"aps"] valueForKey:@"alert"]];
        }
于 2013-08-16T06:06:32.107 回答