gpt4 book ai didi

iphone - PushMeBaby 不起作用!

转载 作者:行者123 更新时间:2023-12-03 21:06:41 25 4
gpt4 key购买 nike

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

- (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 代码:

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

最佳答案

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

如果您想使用推送通知,那么没有比使用Urban Airship更好的方法了。

这里有两个教程,可帮助您启动并运行 Urban Airship :Part 1 & Part 2 (我也可以验证这些是否正常工作,因为我已经多次关注它们)

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

关于iphone - PushMeBaby 不起作用!,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6425250/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com