确定应用是与 APNS 沙箱还是生产环境通信 [英] Determine whether app is communicating with APNS sandbox or production environment

查看:25
本文介绍了确定应用是与 APNS 沙箱还是生产环境通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用中设置了推送通知.我正在尝试确定我在 application:didRegisterForRemoteNotificationsWithDeviceToken: 方法中从 APNS 收到的设备令牌是否来自沙箱或开发环境.如果我能区分哪个环境初始化了令牌,我就可以告诉我的服务器将推送通知发送到哪个环境.

I have push notifications set up in my app. I'm trying to determine whether the device token I've received from APNS in the application:didRegisterForRemoteNotificationsWithDeviceToken: method came from the sandbox or development environment. If I can distinguish which environment initialized the token, I'll be able to tell my server to which environment to send the push notification.

我已经尝试使用 DEBUG 宏来确定这一点,但我看到了一些奇怪的行为,并且不相信它是 100% 正确的.

I've tried using the DEBUG macro to determine this, but I've seen some strange behavior with this and don't trust it to be 100% correct.

#ifdef DEBUG
BOOL isProd = YES;
#else
BOOL isProd = NO;
#endif

理想情况下,我可以检查代码中的 aps-environment 权利(值为 Development 或 Production),但我不确定这是否可行.

Ideally, I'd be able to examine the aps-environment entitlement (value is Development or Production) in code, but I'm not sure if this is even possible.

确定您的应用是与 APNS 沙盒还是生产环境通信的正确方法是什么?我假设服务器首先需要知道这一点.如果假设不正确,请纠正我.

What's the proper way to determine whether your app is communicating with the APNS sandbox or production environments? I'm assuming that the server needs to know this in the first place. Please correct me if this is assumption is incorrect.

编辑:Apple 关于提供者与 APNS 的通信 详细说明了与沙箱通信和生产之间的区别.但是,该文档没有提供有关如何与注册令牌(来自 iOS 客户端应用)和与服务器通信保持一致的信息.

Edited: Apple's documentation on Provider Communication with APNS details the difference between communicating with the sandbox and production. However, the documentation doesn't give information on how to be consistent with registering the token (from the iOS client app) and communicating with the server.

推荐答案

您可以阅读和检查嵌入式配置文件.

You can read and check the embedded provisioning profile.

https://github.com/tcurdt/TCMobileProvision

这就是我所做的:

NSString *mobileprovisionPath = [[[NSBundle mainBundle] bundlePath]
        stringByAppendingPathComponent:@"embedded.mobileprovision"];
TCMobileProvision *mobileprovision = [[TCMobileProvision alloc] initWithData:[NSData dataWithContentsOfFile:mobileprovisionPath]];
NSDictionary *entitlements = mobileprovision.dict[@"Entitlements"];
NSString *apsEnvironment = entitlements[@"aps-environment"];
BOOL production = entitlements && apsEnvironment && [apsEnvironment isEqualToString:@"production"];

这篇关于确定应用是与 APNS 沙箱还是生产环境通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆