确定设备令牌是沙箱还是分发

发布于 2024-11-04 19:20:13 字数 260 浏览 1 评论 0原文

有没有办法确定设备令牌是沙箱还是分发?我们正在测试,应用程序有时使用开发证书进行签名,其他应用程序使用临时证书(分发证书)进行签名。这是因为我们正在将应用程序传递到 100 个提供的临时测试设备中的一些设备,并且还在我们的设备上构建开发签名的应用程序。 因为发送推送通知需要我们选择适当的推送服务器和 pem 文件,所以如果能够确定令牌是沙箱还是分发,以便以适当的方式发送通知,以便推送通知成功,那就太好了。 有时我们必须使用分发配置文件来签署我们的应用程序,因此测试推送通知系统需要我们正确传递这些通知。

Is there a way to determine if a device token is sandbox or distribution? We are testing and the application is sometimes signed with a development certificate and others are signed with an ad hoc certificate(distribution certificate). This is because we are passing the application around to some of the 100 provided ad hoc test devices, and also building development signed apps to our devices.
Because sending a push notification requires that we select the appropriate push server and pem file, it would be great to be able to determine if the token is sandbox or distribution to send the notifications in the appropriate way so that the push notification succeeds.
We must sometimes use the distribution profile to sign our applications, so testing the push notification system requires us to deliver these notifications properly.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

樱娆 2024-11-11 19:20:13
  1. 打开项目构建设置
  2. 转到预处理设置
  3. 在“预编译头中未使用的预处理器宏”下(假设您没有在 .pch 文件中分支代码),在 Release 下添加 TOKEN_ENV_SANDBOX=0,在 Debug 和 Ad Hoc 下添加 TOKEN_ENV_SANDBOX=1。
  4. 在代码中的任何地方只需使用编译器指令

#if !TOKEN_ENV_SANDBOX
NSLog(@"TOKEN_ENV==生产");
#endif

#if TOKEN_ENV_SANDBOX
NSLog(@"TOKEN_ENV==SANDBOX");
#endif

编辑:
修正了上面的一个问题。

  1. Open project build setting
  2. Go to preprocessing settings
  3. Under "Preprocessor macros not used in precompiled headers" (assuming you are not branching code in a .pch file), add TOKEN_ENV_SANDBOX=0 under Release and TOKEN_ENV_SANDBOX=1 under Debug and Ad Hoc.
  4. In your code wherever just use the compiler directive

#if !TOKEN_ENV_SANDBOX
NSLog(@"TOKEN_ENV==PRODUCTION");
#endif

#if TOKEN_ENV_SANDBOX
NSLog(@"TOKEN_ENV==SANDBOX");
#endif

EDIT:
Corrected an issue above.

弄潮 2024-11-11 19:20:13

我阅读了上面的所有答案,它们都是正确的,但没有回答基本问题:“设备令牌是沙箱还是分发?”。

这是因为它们检测构建配置,而不是令牌质量

在花了几天时间解决这个问题后,我找到了直接的解决方案:

测试您通过真正的 Apple Push Notification Server 获得的令牌。您可以使用与服务器通信的简单应用程序,只需对其进行配置即可。

我确实在 macOS 或任何其他操作系统上使用了这个简单的应用程序“Easy APNs Provider”。

https://itunes.apple。 com/us/app/easy-apns-provider-push-notification/id989622350?mt=12

我在 macOS 应用程序中的核心问题是我不断在调试和发布配置中获取生产令牌。

当您检测到问题时,您可以使证书无效,以 100% 确定它不会受到损害。

I read all answers above and they are all correct but do not answer the basic question: "Is device token sandbox or distribution?".

It is because they detect build configuration, not token quality.

After spending several days in resolving this issue, I got to the straigt-forward solution:

Test token you got with real Apple Push Notification Server. You may use simple app that will talk to the server and you just need to configure it.

I did use this simple app "Easy APNs Provider" for macOS or any else.

https://itunes.apple.com/us/app/easy-apns-provider-push-notification/id989622350?mt=12

My core issue in macOS app was that I keep getting production token in both Debug and Release configurations.

When you detect what was an issue, you may invalidate certificates to be 100% sure it will not be compromised.

提赋 2024-11-11 19:20:13

这是苹果公司不得不说的

您可以在 Xcode 中通过选择代码签名身份来确定您所处的环境。如果您看到“iPhone Developer: Firstname Lastname”证书/配置文件对,则说明您处于沙盒环境中。如果您看到“iPhone Distribution: Companyname”证书/配置文件对,则表明您处于生产环境中。

Here is what Apple has to say

You can determine in Xcode which environment you are in by the selection of a code-signing identity. If you see an “iPhone Developer: Firstname Lastname” certificate/provisioning profile pair, you are in the sandbox environment. If you see an “iPhone Distribution: Companyname” certificate/provisioning profile pair, you are in the production environment.

烟雨凡馨 2024-11-11 19:20:13

将预处理器宏添加到 Apple LLVM 7.0 - 预处理下的目标构建设置中。然后在“调试”下添加如下内容:

isRunningInDevModeWithDevProfile=1

然后在 .pch 中,您可以执行如下操作:

// AZ - 01282016 - Determine which environment we are running in for APNS
# ifdef isRunningInDevModeWithDevProfile
#     define isAPNSSandbox YES
#else
#    define isAPNSSandbox NO
#endif

然后在代码中需要检查它的位置,您可以执行以下操作:

NSString *ifAppIsRunningFromXcodeUsingNonReleaseProfile;

if (isAPNSSandbox) {
    ifAppIsRunningFromXcodeUsingNonReleaseProfile = @"dev";
} else {
    ifAppIsRunningFromXcodeUsingNonReleaseProfile = @"prod";
}

我们通过此值返回到我们的 APNS 服务器,以便它知道在调用 Apple 的 APNS 时采取哪条路径。

我建议这样做的原因是,在这种情况下,如果您在非调试目标中未定义预处理器宏,则在尝试构建它时不会导致错误。

当然,有一些具有更好形式的解决方案,但这是启动和运行此功能的一种相当安全且快速的方法。

Add an Preprocessor Macro to your Target's Build Settings under Apple LLVM 7.0 - Preprocessing. Then under Debug add something like:

isRunningInDevModeWithDevProfile=1

Then in your .pch, you can do something like this:

// AZ - 01282016 - Determine which environment we are running in for APNS
# ifdef isRunningInDevModeWithDevProfile
#     define isAPNSSandbox YES
#else
#    define isAPNSSandbox NO
#endif

And then where you need to check it in your code, you can do this:

NSString *ifAppIsRunningFromXcodeUsingNonReleaseProfile;

if (isAPNSSandbox) {
    ifAppIsRunningFromXcodeUsingNonReleaseProfile = @"dev";
} else {
    ifAppIsRunningFromXcodeUsingNonReleaseProfile = @"prod";
}

We pass this value back to our APNS server so that it knows which path to take when calling Apple's APNS.

The reason I suggest this is that in this case, if you leave the preprocessor macro undefined in the non Debug targets, this will not cause an error when you try to build it.

Sure, there are solutions with a better form, but this is is a rather safe and quick way to get this functionality up and running.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文