确定应用程序是否与APNS沙盒或生产环境中的通信 [英] Determine whether app is communicating with APNS sandbox or production environment

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

问题描述

我在我的应用程序设置推送通知。我想确定我已经从APNS在应用程序接收设备令牌是否:didRegisterForRemoteNotificationsWithDeviceToken:方法从沙箱或开发环境来了。如果我能区分哪些环境初始化令牌,我可以告诉我的服务器到环境发送推送通知。

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-环境资格(价值开发或生产)在code,但我不知道这甚至有可能。

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.

编辑:苹果对<一个文档href=\"http://developer.apple.com/library/mac/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingWIthAPS/CommunicatingWIthAPS.html#//apple_ref/doc/uid/TP40008194-CH101-SW1\">Provider与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.

<一个href=\"https://github.com/tcurdt/TCMobileProvision\">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天全站免登陆