PushMeBaby 不起作用! [英] PushMeBaby does not work !

查看:35
本文介绍了PushMeBaby 不起作用!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试根据 [本教程 ,][1] 通过 PushMeBaby 应用程序发送推送通知,但我不知道为什么它不起作用!我从 iTunes 安装了 iPusher 应用程序并且运行良好!这是我的代码:

- (id)init {self = [超级初始化];如果(自我!= 零){self.deviceToken = @"5ce090e5 78d38a8a 149dbe46 cbe87e2e dc6c6d2a 4b97e3b7 a5d3f4c2 b09faad2";self.payload = @"{\"aps\":{\"alert\":\"你收到一条新消息!\",\"badge\":5,\"sound\":\"beep.wav\"},\"acme1\":\"bar\",\"acme2\":42}";self.certificate = [[NSBundle mainBundle]pathForResource:@"aps_developer_identity" ofType:@"cer"];}回归自我;}

URBan AirShip 代码:

 (void)application:(UIApplication*)applicationdidRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken{//TODO:将令牌传递给我们的服务器//将标记转换为十六进制字符串并确保全部大写NSMutableString *tokenString = [NSMutableString stringWithString:[[deviceToken description] uppercaseString]];[tokenString replaceOccurrencesOfString:@"<"withString:@"" options:0 range:NSMakeRange(0, tokenString.length)];[tokenString replaceOccurrencesOfString:@">"withString:@"" options:0 range:NSMakeRange(0, tokenString.length)];[tokenString replaceOccurrencesOfString:@" " withString:@"" options:0 range:NSMakeRange(0, tokenString.length)];//为请求创建 NSURLNSString *urlFormat = @"https://go.urbanairship.com/api/device_tokens/%@";NSURL *registrationURL = [NSURL URLWithString:[NSString stringWithFormat:urlFormat, tokenString]];//创建注册请求NSMutableURLRequest *registrationRequest = [[NSMutableURLRequest alloc]initWithURL:registrationURL];[注册请求 setHTTPMethod:@"PUT"];//并关闭它NSURLConnection *connection = [NSURLConnection connectionWithRequest:registrationRequest委托:自己];[连接开始];NSLog(@"我们成功注册了推送通知");}- (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error{//通知用户注册失败NSString* failureMessage = @"尝试/注册推送通知时出错.";UIAlertView* failureAlert = [[UIAlertView alloc] initWithTitle:@"Error"消息:失败消息代表:无取消按钮标题:@"好的"otherButtonTitles:nil];[故障提示显示];[故障警报发布];}- (void)connection:(NSURLConnection *)connectiondidReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge{//检查之前的失败if ([挑战previousFailureCount] > 0){//我们已经尝试过 - 我们的凭据有问题NSLog(@"城市飞艇凭证无效");返回;}//发送我们的城市飞艇凭证NSURLCredential *airshipCredentials = [NSURLCredential credentialWithUser:@"<GY__T8X4Rg6onkJSO8o0Bg>"密码:@""持久性:NSURLCredentialPersistenceNone];[[挑战发送者] useCredential:airshipCredentialsforAuthenticationChallenge:challenge];}

解决方案

我已经通读了你在 mobiforge 上遵循的教程,它在很多层面上都是错误的!

如果您想使用推送通知,那么确实没有比使用Urban Airship

这里有两个教程可以让您开始使用 Urban Airship:第 1 部分 &第 2 部分(我也可以验证这些工作正确,因为我已经多次关注他们)

如果您想避免使用第三方,而是可以访问您自己的支持 PHP 的服务器,那么这里有另一对教程可以帮助您进行设置:第 1 部分 &第 2 部分

I am trying to send push notification via PushMeBaby app according to [this tutorial ,][1] but I don't know why it does not work ! I install iPusher App from itunes and worked fine ! here is my code :

- (id)init {
    self = [super init];

    if(self != nil) {
        self.deviceToken = @"5ce090e5 78d38a8a 149dbe46 cbe87e2e dc6c6d2a 4b97e3b7 a5d3f4c2 b09faad2";

        self.payload = @"{\"aps\":{\"alert\":\"You got a new message!\",\"badge\":5,\"sound\":\"beep.wav\"},\"acme1\":\"bar\",\"acme2\":42}";

        self.certificate = [[NSBundle mainBundle] 
                            pathForResource:@"aps_developer_identity" ofType:@"cer"];
    }
    return self;

}

URBan AirShip code :

 (void)application:(UIApplication*)application  
didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken  
{  
    // TODO: Pass the token to our server  
    // Convert the token to a hex string and make sure it's all caps  
    NSMutableString *tokenString = [NSMutableString stringWithString:[[deviceToken description] uppercaseString]];  
    [tokenString replaceOccurrencesOfString:@"<" withString:@"" options:0 range:NSMakeRange(0, tokenString.length)];  
    [tokenString replaceOccurrencesOfString:@">" withString:@"" options:0 range:NSMakeRange(0, tokenString.length)];  
    [tokenString replaceOccurrencesOfString:@" " withString:@"" options:0 range:NSMakeRange(0, tokenString.length)];  

    // Create the NSURL for the request  
    NSString *urlFormat = @"https://go.urbanairship.com/api/device_tokens/%@";  
    NSURL *registrationURL = [NSURL URLWithString:[NSString stringWithFormat:  
                                                   urlFormat, tokenString]];  
    // Create the registration request  
    NSMutableURLRequest *registrationRequest = [[NSMutableURLRequest alloc]  
                                                initWithURL:registrationURL];  
    [registrationRequest setHTTPMethod:@"PUT"];  

    // And fire it off  
    NSURLConnection *connection = [NSURLConnection connectionWithRequest:registrationRequest  
                                                                delegate:self];  
    [connection start];  




    NSLog(@"We successfully registered for push notifications");  
}  

- (void)application:(UIApplication*)application  didFailToRegisterForRemoteNotificationsWithError:(NSError*)error  
{  
    // Inform the user that registration failed  
    NSString* failureMessage = @"There was an error while trying to / register for push notifications.";  
    UIAlertView* failureAlert = [[UIAlertView alloc] initWithTitle:@"Error"  
                                                           message:failureMessage  
                                                          delegate:nil  
                                                 cancelButtonTitle:@"OK"  
                                                 otherButtonTitles:nil];  
    [failureAlert show];  
    [failureAlert release];  
}  






- (void)connection:(NSURLConnection *)connection  
didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge  
{  
    // Check for previous failures  
    if ([challenge previousFailureCount] > 0)  
    {  
        // We've already tried - something is wrong with our credentials  
        NSLog(@"Urban Airship credentials invalid");  
        return;  
    }  

    // Send our Urban Airship credentials  
    NSURLCredential *airshipCredentials = [NSURLCredential credentialWithUser:@"<GY__T8X4Rg6onkJSO8o0Bg>"  
                                                                     password:@"<Z_fhEasrQ6emwFcWMyiKrA>"  
                                                                  persistence:NSURLCredentialPersistenceNone];  
    [[challenge sender] useCredential:airshipCredentials  
           forAuthenticationChallenge:challenge];  
} 

解决方案

I have read through the tutorial you've followed on mobiforge and it is wrong on so many levels!

If you want to use Push Notifications, then there really is no better way than to use Urban Airship

Here are a pair of tutorials which will get you up and running using Urban Airship: Part 1 & Part 2 (I can also verify these work properly as I have followed them many times)

If you would like avoid using a third party and instead have access to your own PHP capable server then here is another pair of tutorials which will help you get setup: Part 1 & Part 2

这篇关于PushMeBaby 不起作用!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆