2011-09-28 112 views
0

我「認爲」我的應用程序沒有註冊推送通知。iPhone客戶端未註冊推送?

它應該和將代碼添加到didFinishLaunchingWithOptions一樣簡單,然後在測試應用程序警報時推送通知應該(但不在我的情況下)彈出。

我的代碼:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
// Override point for customization after application launch. 

self.window.rootViewController = self.viewController; 
[self.window makeKeyAndVisible]; 

[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge |UIRemoteNotificationTypeSound)]; 

return YES; 
} 

這是一個iPad應用程序。它在沒有推動我的真實設備的情況下運行,所以我認爲配置是正確的。

任何想法?我不推動不要/允許彈出。

push

回答

1

不要ü有你的委託這個代碼?

- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { 

    NSString *str = [NSString 
     stringWithFormat:@"Device Token=%@",deviceToken]; 
    NSLog(str); 

} 

你應該得到所產生的設備令牌並把它放在你想要把你通知你的服務器..

如果比方說您有權對iPhone的一部分一切,問題可能位於在那裏你把你的通知,您的服務器代碼..

看看本教程的推送通知: http://mobiforge.com/developing/story/programming-apple-push-notification-services

+0

是的。在旁註中,我是否需要將設備令牌發送到我的服務器,如果是這樣的話?和哪裏? – Rick

+0

是的,你需要將設備令牌發送到服務器。一旦你從上述方法獲得令牌,通過網絡發送令牌給你的服務器。對於服務器端的示例/代碼..你可以嘗試去上面的鏈接.. – sicKo

1

您需要實現的委託方法,並建立了CER證書在您的服務器上。下面是objc側一些代碼:

- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken { 
    NSString *token = [[devToken description] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]]; 
    [[NSUserDefaults standardUserDefaults] setObject:token forKey:@"token"]; 
    [[NSUserDefaults standardUserDefaults] synchronize]; 
} 

- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err { 
    [[NSUserDefaults standardUserDefaults] setObject:[NSString stringWithString:@""] forKey:@"token"]; 
    [[NSUserDefaults standardUserDefaults] synchronize]; 
} 

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { 
    UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"] 
                message:[[userInfo objectForKey:@"aps"] objectForKey:@"alert"] 
                delegate:self 
              cancelButtonTitle:@"OK" 
              otherButtonTitles:nil] autorelease]; 
    [alert show]; 
} 
0

是的,我有代碼的其他部分也是如此。我的印象是,彈出窗口會發生天氣服務器的東西已經完成或沒有?

我明白了。我必須得到一個新的配置文件。刪除舊的。進入應用程序文件夾。查看項目文件的內容。用文本編輯器打開配置密鑰的文件,並用新的密鑰代碼交換密鑰(兩個點)。

現在,它的工作。謝謝您的幫助。