0

我已經嘗試了很多教程來發送推送通知服務爲我的應用程序。當我在設備上測試它的工作。但如果我在應用程序啓動後在App Store上進行實時測試,並通過從商店下載並將其安裝到我的設備上,並運行用於發送推送通知的php文件,我沒有收到它。這裏是代碼我用於推送通知和我從中學到的tutorial關於ios的實時推送通知教程

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

是否有可以教我擁有了它live.I任何教程從沙箱改變了我的PHP文件的環境live.Guidance請。

+0

您是否爲生產服務器使用了正確的ssl證書?您無法使用沙盒證書連接到生產服務器。 – Sascha 2012-08-13 09:45:18

+0

是的,我使用正確的SSL證書生產服務器.. – Dany 2012-08-13 09:47:21

+0

@Sascha:是我的編碼是正確的? – Dany 2012-08-13 09:47:53

回答

2

我自己解決了這個問題。

原因沒有工作,那麼在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"); 

} 
1

首先,我不認爲使用開發推送通知證書(或臨時證書)安裝應用程序,獲取deviceToken,安裝應用商店應用程序並使用先前的設備令牌發送推送通知將可用。

此鏈接證實了這一點:iPhone APNS Device Tokens in sandbox vs. production

這也許就是爲什麼你不能發送推送通知到你的應用程序。

此外,您需要將設備令牌發送到您的服務器,這是您的服務器知道所有設備令牌的唯一方法。

我建議您查看。