我已经尝试了太多的教程来为我的app.When发送推送通知服务,我正在设备上测试它,它是有效的。但是,如果我在app store上启动应用程序后在现场测试它,并通过从商店下载将其安装在我的设备上,然后运行php文件发送推送通知,我得不到it.Here是我用于推送通知的代码和我从中学到的tutorial。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
return YES;
}
- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
{
NSLog(@"My token is: %@", deviceToken);
}
- (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error
{
NSLog(@"Failed to get token, error: %@", error);
}有没有什么教程可以教我把它放在have上呢?我把我的php文件的环境从沙箱改成了live.Guidance。
发布于 2013-03-08 17:22:18
我自己解决了这个问题。
不能在Live上工作的原因是因为
(空)应用程序:(UIApplication*)应用程序didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
在这个方法中,设备令牌没有正确地注册到我的php服务器数据库中。以下代码将帮助您在php服务器中注册设备令牌。
- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
{
NSLog(@"My token is: %@", deviceToken);
NSString* newToken = [deviceToken description];
newToken = [newToken stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]];
newToken = [newToken stringByReplacingOccurrencesOfString:@" " withString:@""];
NSLog(@"%@",newToken);
NSString *urlString = [NSString stringWithFormat:@"http://sample.com/registerDevice.php?appId=xxx&deviceToken=%@",newToken];
NSURL *url = [[NSURL alloc] initWithString:urlString];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
NSData *urlData;
NSURLResponse *response;
urlData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:nil];
NSLog(@"data send");
}发布于 2012-08-13 20:34:17
首先,我不认为使用开发推送通知证书(或ad-hoc证书)安装应用程序、获取deviceToken、安装应用商店应用程序并使用以前的设备令牌发送推送通知是可行的。
这个链接证实了这一点:iPhone APNS Device Tokens in sandbox vs. production
这可能解释了为什么你不能向你的应用程序发送推送通知。
此外,您还需要将设备令牌发送到您的服务器,因为这是您的服务器知道所有设备令牌的唯一方法。
我建议你复习一下apple documentation。
https://stackoverflow.com/questions/11931700
复制相似问题