如何使用 PushMeBaby 示例发送 Apple 推送通知?

发布于 2024-08-19 23:43:46 字数 982 浏览 5 评论 0原文

我正在尝试使用 PushMeBaby 示例 APN 服务器应用程序将推送通知发送到我的设备。我有临时分发应用程序。对于我的应用程序 ID,我创建了用于开发和生产的 ssl 证书。它似乎没有从 PushMeBaby 应用程序发送推送通知,我已经将 Push SSL 证书安装到工具链.. 仍然似乎不起作用..

2010-02-01 07:20:49.578 PushMeBaby[7193:a0f] MakeServerConnection(): 0
2010-02-01 07:20:49.613 PushMeBaby[7193:a0f] SSLNewContext(): 0
2010-02-01 07:20:49.614 PushMeBaby[7193:a0f] SSLSetIOFuncs(): 0
2010-02-01 07:20:49.614 PushMeBaby[7193:a0f] SSLSetConnection(): 0
2010-02-01 07:20:49.615 PushMeBaby[7193:a0f] SSLSetPeerDomainName(): 0
2010-02-01 07:20:49.631 PushMeBaby[7193:a0f] SecKeychainOpen(): 0
2010-02-01 07:20:49.648 PushMeBaby[7193:a0f] SecCertificateCreateFromData(): 0
2010-02-01 07:20:49.655 PushMeBaby[7193:a0f] SecIdentityCreateWithCertificate(): 0
2010-02-01 07:20:49.656 PushMeBaby[7193:a0f] SSLSetCertificate(): 0
2010-02-01 07:20:52.353 PushMeBaby[7193:a0f] SSLHandshake(): 0
2010-02-01 07:20:57.954 PushMeBaby[7193:a0f] SSLWrite(): 0 144

以上是 PusheBaby xcode 应用程序的日志。

I am trying to use PushMeBaby sample APN Server application to send push notifications to my device. I have adhoc distribution application. For my application ID I have created both ssl certificates for development and production. It seems to be not sending push notifications from PushMeBaby application, I have alread installed Push SSL certificates to the tool chain.. still it seems to be not working..

2010-02-01 07:20:49.578 PushMeBaby[7193:a0f] MakeServerConnection(): 0
2010-02-01 07:20:49.613 PushMeBaby[7193:a0f] SSLNewContext(): 0
2010-02-01 07:20:49.614 PushMeBaby[7193:a0f] SSLSetIOFuncs(): 0
2010-02-01 07:20:49.614 PushMeBaby[7193:a0f] SSLSetConnection(): 0
2010-02-01 07:20:49.615 PushMeBaby[7193:a0f] SSLSetPeerDomainName(): 0
2010-02-01 07:20:49.631 PushMeBaby[7193:a0f] SecKeychainOpen(): 0
2010-02-01 07:20:49.648 PushMeBaby[7193:a0f] SecCertificateCreateFromData(): 0
2010-02-01 07:20:49.655 PushMeBaby[7193:a0f] SecIdentityCreateWithCertificate(): 0
2010-02-01 07:20:49.656 PushMeBaby[7193:a0f] SSLSetCertificate(): 0
2010-02-01 07:20:52.353 PushMeBaby[7193:a0f] SSLHandshake(): 0
2010-02-01 07:20:57.954 PushMeBaby[7193:a0f] SSLWrite(): 0 144

Above is the log of PusheBaby xcode application.

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

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

发布评论

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

评论(4

迷迭香的记忆 2024-08-26 23:43:46

好的 - 弄清楚了。

我传入的设备令牌(从 UrbanAirship 获得)没有空格。我根据这个很棒的教程 (http://mobiforge.com/developing/story/programming-apple-push-notification-services) 使用了 iPhone 应用程序控制台中的设备令牌,该令牌在字符串中每 8 个字符之间有空格。这就成功了。

设备令牌应如下所示 - 38c866dd bb323b39 ffa73487 5e157ee5 a85e0b7c e90d56e9 fe145bcc 6c2c594b

稍后 - 当您查看 PushMeBaby 的 NSLog 时 - 您将看到 SSLWrite 调用中的“已处理”计数增加了 1(我的从 104 增加到 105)
例如 2011-04-28 11:21:41.543 PushMeBaby[49218:903] SSLWrite(): 0 105

希望这可以帮助那些像我一样挣扎了几天的人......

OK - Figured this out.

The device token I was passing in (which I got from UrbanAirship) had no spaces. I used the device token from the console from the iPhone app per this great tutorial (http://mobiforge.com/developing/story/programming-apple-push-notification-services) which has spaces between every 8 chars in the string. That did the trick.

The device token should look like this - 38c866dd bb323b39 ffa73487 5e157ee5 a85e0b7c e90d56e9 fe145bcc 6c2c594b

Later - when you look at the NSLog from PushMeBaby - you will see the "processed" count in the SSLWrite call increased by 1 (mine went from 104 to 105)
e.g. 2011-04-28 11:21:41.543 PushMeBaby[49218:903] SSLWrite(): 0 105

Hope this helps somebody else who struggled like me for days...

ㄟ。诗瑗 2024-08-26 23:43:46

我只是想在这里加上我的两分钱,因为这也让我受益匪浅。如果您意识到设备令牌应该有空格,那么为了不再出现此问题,请将这部分代码替换

    // Validate input.
    if(self.deviceToken == nil || self.payload == nil) {
        return;
    }

为:

    // Validate input.
    if(self.deviceToken == nil || self.payload == nil) {
        return;
    }
    else if(![self.deviceToken rangeOfString:@" "].length)
    {
        //put in spaces in device token
        NSMutableString* tempString =  [NSMutableString stringWithString:self.deviceToken];
        int offset = 0;
        for(int i = 0; i < tempString.length; i++)
        {
            if(i%8 == 0 && i != 0 && i+offset < tempString.length-1)
            {
                //NSLog(@"i = %d + offset[%d] = %d", i, offset, i+offset);
                [tempString insertString:@" " atIndex:i+offset];
                offset++;
            }
        }
        NSLog(@" device token string after adding spaces = '%@'", tempString);
        self.deviceToken = tempString;
    }

Just thought I'd add my two cents here since this got me too. If you realized that the device token should have had spaces, then to never have this problem again replace this section of code:

    // Validate input.
    if(self.deviceToken == nil || self.payload == nil) {
        return;
    }

with this:

    // Validate input.
    if(self.deviceToken == nil || self.payload == nil) {
        return;
    }
    else if(![self.deviceToken rangeOfString:@" "].length)
    {
        //put in spaces in device token
        NSMutableString* tempString =  [NSMutableString stringWithString:self.deviceToken];
        int offset = 0;
        for(int i = 0; i < tempString.length; i++)
        {
            if(i%8 == 0 && i != 0 && i+offset < tempString.length-1)
            {
                //NSLog(@"i = %d + offset[%d] = %d", i, offset, i+offset);
                [tempString insertString:@" " atIndex:i+offset];
                offset++;
            }
        }
        NSLog(@" device token string after adding spaces = '%@'", tempString);
        self.deviceToken = tempString;
    }
写给空气的情书 2024-08-26 23:43:46

设备令牌应该是

45f62964 06523099 b66017f7 0eb3ea7d 14140c11 af6f14a0 c24145d1 90005763

not
<45f62964 06523099 b66017f7 0eb3ea7d 14140c11 af6f14a0 c24145d1 90005763>
or
45f6296406523099b66017f70eb3ea7d14140c11af6f14a0c24145d190005f9c

是的,对于 Push me Baby ,如果您包含 <>, 它在 NSScanner 中进入无限循环,

尽管正式设备令牌应包含 <>和空格,这就是您注册设备时得到的
如果您在其他应用程序中使用它,例如 MAC APP STORE 上的 APN TESTER

<45f62964 06523099 b66017f7 0eb3ea7d 14140c11 af6f14a0 c24145d1 90005763>

yes for Push me baby the device token should be

45f62964 06523099 b66017f7 0eb3ea7d 14140c11 af6f14a0 c24145d1 90005763

not
<45f62964 06523099 b66017f7 0eb3ea7d 14140c11 af6f14a0 c24145d1 90005763>
or
45f6296406523099b66017f70eb3ea7d14140c11af6f14a0c24145d190005f9c

if you include the <> it goes into an infinite loop in an NSScanner

Though officially the device token should include <> and spaces as thats what you get when you RegisterDevice
if you use it in other apps such as APN TESTER on MAC APP STORE

<45f62964 06523099 b66017f7 0eb3ea7d 14140c11 af6f14a0 c24145d1 90005763>
还在原地等你 2024-08-26 23:43:46

只需将其添加

// Convert string into device token data.

ApplicationDelegate.h 中的 -(IBAction)push:(id)sender; 之前即可。

if (![self.deviceToken rangeOfString:@" "].length) {
    NSMutableString *string = [self.deviceToken mutableCopy];
    for (int i = 8; i < string.length; i+=8) {
        [string insertString:@" " atIndex:i];
    }
    self.deviceToken = string;
}

现在您支持“无空间”格式。

Just add this before

// Convert string into device token data.

to -(IBAction)push:(id)sender; in ApplicationDelegate.h.

if (![self.deviceToken rangeOfString:@" "].length) {
    NSMutableString *string = [self.deviceToken mutableCopy];
    for (int i = 8; i < string.length; i+=8) {
        [string insertString:@" " atIndex:i];
    }
    self.deviceToken = string;
}

And now you it is supported the "spaceless" format.

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