關於推送的機制和推送用到的認證問題在這裡不多說。
關於推送的代碼部分:
用戶端:
1、告訴應用程式,接收push來的訊息(當然是放在 didFinishLaunchingWithOptions 方法裡面了)
[application registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeSound];
2、完成推送比不可缺的東西:deviceToken ,蘋果推送會根據 deviceToken的值進行推送的操作。deviceToken和全球之內的蘋果裝置一一對應的,也就是說它是唯一的。
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { NSLog(@"擷取裝置的deviceToken: %@", deviceToken);}- (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error{ NSLog(@"Failed to get token, error: %@", error);
3、對推送過來的訊息進行處理的方法:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{ //以警告框的方式來顯示推送訊息 if ([[userInfo objectForKey:@"aps"] objectForKey:@"alert"]!=NULL) { UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"經過推送發送過來的訊息" message:[[userInfo objectForKey:@"aps"] objectForKey:@"alert"] delegate:self cancelButtonTitle:@"關閉" otherButtonTitles:@"處理",nil]; [alert show]; [alert release]; }}
php伺服器端:
點擊開啟連結
java伺服器端:
點擊開啟連結