利用推送测试工具,测试推送是否写好

  • 网上有很多的测试推送的工具,譬如 Easy APNs Provider 还有 SmartPush 的github

  • 方式都差不多,选择推送证书,输入deviceToken,连接苹果的服务器,两种一种是测试环境的,一种是生产环境的,测试环境中,你可以直接打断点获得deviceToken,而如果你是用adHoc导出的生产环境测试,只好利用这一种方式了,将token字符串写入沙盒。

  • 写入沙盒文件:

+(void)writToken:(NSString *)token{
    NSString* documentPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    NSString* totalPath = [documentPath stringByAppendingPathComponent:@"aa"];
    [token writeToFile:totalPath atomically:NO encoding:NSUTF8StringEncoding error:nil];
}

为了方便把空格和'<' '>'符号去掉

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
    NSString *token = [[[deviceToken description]
                        stringByReplacingOccurrencesOfString: @"<" withString: @""]
                       stringByReplacingOccurrencesOfString: @">" withString: @""];

    NSLog(@"token:%@",token);
    [TestLocalNotifaction writToken:[token replace:@" " to:@""]];
    // push token to php server
    PushTokenToPhp();
}
  • 然后从沙盒中获得信息, Xcode中按Ctrl+shift+2,进入设备列表导出沙盒,查看你刚刚写入的token

猜你喜欢

转载自www.cnblogs.com/RoysPhoneBlog/p/9369662.html