【发布时间】:2015-04-09 12:50:15
【问题描述】:
我正在创建一个安装在 /Applications 中的越狱应用程序。无论我做什么,我似乎都无法让推送通知工作。
我有:
- 在 Apple 开发者控制台中创建了必要的 App ID,
- 创建了所有必要的证书和规定,
- 必要时安装以上,
- 使用相应的证书对应用进行签名,
- 将 .MobileProvision 文件中的内容添加到权限中,
- 用头撞墙。
症状如下。我成功注册了 APNS 并获得了一个设备令牌。设备令牌已成功发送到我的服务器。我的服务器成功连接到 APNS 服务器,成功地向 APNS 服务器发送了推送通知,没有任何形式的投诉,而且我的应用程序永远不会收到推送消息。它只是迷路了。我是用越狱的 ios 7 设备还是越狱的 ios 8 设备进行测试都没有关系。据我所知,这两款设备都成功获取了其他应用的 APNS 消息。
我已尝试过开发人员和生产设置。
对于我错过的越狱应用程序,是否有一些必要的步骤通常在定期注册应用程序时为您完成?系统应用是否不能成为 APNS 应用(这看起来很奇怪)?
这里有一些代码。手机端(Swift):
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool
{
if Global.OSVersion() < 800
{
application.registerForRemoteNotificationTypes(UIRemoteNotificationType.Alert
| UIRemoteNotificationType.Badge
| UIRemoteNotificationType.Sound);
}
else
{
var types: UIUserNotificationType = UIUserNotificationType.Alert
| UIUserNotificationType.Badge
| UIUserNotificationType.Sound;
var settings: UIUserNotificationSettings = UIUserNotificationSettings(forTypes: types,
categories: nil);
application.registerUserNotificationSettings(settings);
}
application.beginReceivingRemoteControlEvents();
}
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData)
{
let bytes: [Byte] = deviceToken.getBytes();
var token: String = "";
for byte: Byte in bytes
{
token += NSString(format: "%02.2hhx", byte);
}
// code to send token to server goes here...
}
func application(application: UIApplication,
didReceiveRemoteNotification userInfo: [NSObject : AnyObject],
fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void)
{
let command: String = userInfo["Command"] as String;
// code to process command goes here...
}
服务器代码(C#):
private bool SendIPhone()
{
isSent = false;
PushBroker pushBroker = new PushBroker();
try
{
pushBroker.OnChannelCreated += pushBroker_OnChannelCreated;
pushBroker.OnChannelException += pushBroker_OnChannelException;
pushBroker.OnChannelDestroyed += pushBroker_OnChannelDestroyed;
pushBroker.OnServiceException += pushBroker_OnServiceException;
pushBroker.OnNotificationFailed += pushBroker_OnNotificationFailed;
pushBroker.OnNotificationSent += pushBroker_OnNotificationSent;
pushBroker.OnNotificationRequeue += pushBroker_OnNotificationRequeue;
pushBroker.OnDeviceSubscriptionChanged += pushBroker_OnDeviceSubscriptionChanged;
pushBroker.OnDeviceSubscriptionExpired += pushBroker_OnDeviceSubscriptionExpired;
pushBroker.RegisterAppleService(new ApplePushChannelSettings(XXXConfig.APNSIsProduction,
XXXStatic.APNSCertificate,
XXXConfig.APNSPassword));
AppleNotification notification = new AppleNotification();
notification.DeviceToken = cloudToPhoneID;
notification.Payload.Alert.Body = "This is a test";
notification.Payload.Sound = "Alarm.wav";
notification.Payload.Badge = 5;
notification.Payload.CustomItems["content-available"] = new Object[] { "1" };
notification.Payload.CustomItems["Command"] = new Object[] { "TestCommand" };
pushBroker.QueueNotification(notification);
}
finally
{
pushBroker.StopAllServices(); // This will force us to wait until we have sent what's in the queue...
}
return isSent;
}
void pushBroker_OnNotificationSent(object sender, INotification notification)
{
isSent = true;
}
有很多代码我并没有显示所有代码都按预期工作。 SendIPhone 始终返回 true,并且只有在调用 pushBroker_OnNotificationSent 时才能设置为 true。
权利:
<dict>
<key>application-identifier</key>
<string>REMOVEDFORPRIVACY</string>
<key>aps-environment</key>
<string>development</string>
<key>com.apple.developer.team-identifier</key>
<string>REMOVEDFORPRIVACY</string>
<key>get-task-allow</key>
<true/>
<key>keychain-access-groups</key>
<array>
<string>REMOVEDFORPRIVACY</string>
</array>
</dict>
我错过了什么或者从这里没有路径?
【问题讨论】:
-
推送通知的一个常见错误是使用您的分发证书但将推送发送到 Apple 的开发推送通知服务器。您确定您设置的分发/开发环境正确吗?
-
是的。我目前只有这个项目的开发证书,正是因为这个原因,我摆脱了所有与生产相关的东西。非常感谢这个建议,但我确实认为我已经涵盖了这个。
-
你有没有得到这个工作?我也遇到了同样的问题。
-
我感觉问题在于我们如何构建/签署应用程序。
-
很可能是 Apple 没有为推送通知启用 /Applications。
标签: ios apple-push-notifications jailbreak