用APNS Tool测试推送证书是否有效,结合真机运行demo实验

    xiaoxiao2026-09-10  2

    iOS开发中,在做推送测试中经常会收不到通知而不知道原因,常常的原因是推送证书无效,token与证书不匹配,怎么验证推送证书的有效性呢,可以用mac电脑从appstore上下载 APNS Tool软件,

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. //APNS注册通知 if ([UIDevice currentDevice].systemVersion.doubleValue<8.0) { [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeBadge)]; } else { [[UIApplication sharedApplication] registerForRemoteNotifications]; [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge|UIUserNotificationTypeSound|UIUserNotificationTypeAlert categories:nil]]; } //判断是否由远程消息通知触发应用程序启动 if (launchOptions) { //获取应用程序消息通知标记数(即小红圈中的数字) NSInteger badge = [UIApplication sharedApplication].applicationIconBadgeNumber; if (badge>0) { //如果应用程序消息通知标记数(即小红圈中的数字)大于0,清除标记。 badge--; //清除标记。清除小红圈中数字,小红圈中数字为0,小红圈才会消除。 [UIApplication sharedApplication].applicationIconBadgeNumber = badge; NSDictionary *pushInfo = [launchOptions objectForKey:@"UIApplicationLaunchOptionsRemoteNotificationKey"]; UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:[NSString stringWithFormat:@"%@,您可以在消息设置那里进行查看",[[pushInfo objectForKey:@"aps"] objectForKey:@"alert"]] delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil]; [alert show]; } } [UIApplication sharedApplication].applicationIconBadgeNumber = 0; return YES; } - (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { NSString * saveDeviceToken = [[deviceToken description] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]]; NSLog(@"saveDeviceToken is:%@", saveDeviceToken); }
    转载请注明原文地址: https://ju.6miu.com/read-1311934.html
    最新回复(0)