PushMeBaby不行! [英] PushMeBaby does not work !

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

问题描述

我试图根据经由PushMeBaby应用程序发送推送通知[本教程] [1],但我不知道为什么它不工作!我从iTunes安装iPusher应用和精细的工作!这里是我的code:

   - (ID)初始化{
    自= [超级初始化]    如果(自我!=无){
        self.deviceToken = @5ce090e5 78d38a8a 149dbe46 cbe87e2e dc6c6d2a 4b97e3b7 a5d3f4c2 b09faad2        self.payload = @{\\APS \\:{\\戒备\\:\\你有新邮件\\,\\徽章!\\:5,\\声音\\:\\beep.wav \\} \\ACME1 \\:\\吧\\,\\acme2 \\:42};        self.certificate = [[一个NSBundle mainBundle]
                            pathForResource:@aps_developer_identityofType:@CER];
    }
    返回自我;}

城市飞艇code:

 (无效)应用:(*的UIApplication)的应用
didRegisterForRemoteNotificationsWithDeviceToken:(NSData的*)deviceToken
{
    // TODO:通过令牌到我们的服务器
    //将令牌一个十六进制字符串,并确保它的全部大写
    *的NSMutableString = tokenString [的NSMutableString stringWithString:[deviceToken说明】uppercaseString]];
    [tokenString replaceOccurrencesOfString:@< withString:@选项:0范围:NSMakeRange(0,tokenString.length)];
    [tokenString replaceOccurrencesOfString:@>中withString:@选项:0范围:NSMakeRange(0,tokenString.length)];
    [tokenString replaceOccurrencesOfString:@withString:@选项:0范围:NSMakeRange(0,tokenString.length)];    //对于请求创建NSURL
    * NSString的网址格式= @https://go.urbanairship.com/api/device_tokens/%@
    NSURL * registrationURL = [NSURL URLWithString:[的NSString stringWithFormat:
                                                   网址格式,tokenString]];
    //创建注册请求
    NSMutableURLRequest * registrationRequest = [[NSMutableURLRequest页头]
                                                initWithURL:registrationURL];
    [registrationRequest setHTTPMethod:@PUT];    //和消防它关闭
    NSURLConnection的*连接= [NSURLConnection的connectionWithRequest:registrationRequest
                                                                委托:自我];
    [连接开始];
    的NSLog(@我们成功注册推送通知);
} - (无效)应用:(*的UIApplication)的应用didFailToRegisterForRemoteNotificationsWithError:(NSError *)错误
{
    //通知注册失败的用户
    * NSString的failureMessage = @有试图/注册推送通知的错误。
    UIAlertView中* failureAlert = [[UIAlertView中页头] initWithTitle:@错误
                                                           消息:failureMessage
                                                          代表:无
                                                 cancelButtonTitle:@OK
                                                 otherButtonTitles:无];
    [failureAlert秀]
    [failureAlert发布​​]
}
- (无效)连接:(NSURLConnection的*)连接
didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)的挑战
{
    //检查previous失败
    如果([挑战previousFailureCount] 0)
    {
        //我们已经尝试过 - 什么是错与我们的凭据
        的NSLog(@城市飞艇凭证无效);
        返回;
    }    //发送我们的城市飞艇凭据
    NSURLCredential * airshipCredentials = [NSURLCredential credentialWithUser:@< GY__T8X4Rg6onkJSO8o0Bg>中
                                                                     密码:@< Z_fhEasrQ6emwFcWMyiKrA>中
                                                                  持久性:NSURLCredentialPersistenceNone];
    [挑战发件人] useCredential:airshipCredentials
           forAuthenticationChallenge:挑战]
}


解决方案

我已经经历了您遵循上mobiforge教程阅读,这是错误的这么多层次!

如果你想使用推送通知,则实在是没有比使用城市飞艇

下面是一对的教程,这将让你和使用城市飞艇运行:第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天全站免登陆