简体   繁体   English

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

[英]How to use PushMeBaby sample to send Apple Push Notifications?

I am trying to use PushMeBaby sample APN Server application to send push notifications to my device. 我正在尝试使用PushMeBaby示例APN Server应用程序向我的设备发送推送通知。 I have adhoc distribution application. 我有adhoc发行申请。 For my application ID I have created both ssl certificates for development and production. 对于我的应用程序ID,我已经为开发和生产创建了两个ssl证书。 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.. 它似乎没有从PushMeBaby应用程序发送推送通知,我已经将安装的推送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

Above is the log of PusheBaby xcode application. 以上是PusheBaby xcode应用程序的日志。

OK - Figured this out. 好的 - 想出来了。

The device token I was passing in (which I got from UrbanAirship) had no spaces. 我传入的设备令牌(我从UrbanAirship获得)没有空格。 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. 我根据这个伟大的教程(http://mobiforge.com/developing/story/programming-apple-push-notification-services)从iPhone应用程序的控制台中使用了设备令牌,该字符串中每8个字符之间有空格。 That did the trick. 这就是诀窍。

The device token should look like this - 38c866dd bb323b39 ffa73487 5e157ee5 a85e0b7c e90d56e9 fe145bcc 6c2c594b 设备令牌应如下所示 - 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) eg 2011-04-28 11:21:41.543 PushMeBaby[49218:903] SSLWrite(): 0 105 稍后 - 当您从PushMeBaby查看NSLog时 - 您将看到SSLWrite调用中的“已处理”计数增加1(我的从104变为105)例如2011-04-28 11:21:41.543 PushMeBaby [49218:903 ] SSLWrite():0 105

Hope this helps somebody else who struggled like me for days... 希望这可以帮助像我这样挣扎好几天的人......

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;
    }

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 如果你包含<>它会进入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 虽然正式设备令牌应该包含<>和空格,因为如果您在其他应用程序(例如MAC APP STORE上的APN TESTER)中使用它,那么您在RegisterDevice时会得到什么

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

Just add this before 只需在此之前添加

// Convert string into device token data.

to -(IBAction)push:(id)sender; to -(IBAction)push:(id)sender; in ApplicationDelegate.h . 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. 而现在你支持“无空间”格式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM