你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> iOS 推送 獲取手機設備的 deviceToken

iOS 推送 獲取手機設備的 deviceToken

編輯:IOS開發綜合


第一步:申請證書:


\


第二步:申請app ids,應用名字必須一致。然後再進入進行編輯,使其enable,綠燈。<喎?/kf/ware/vc/" target="_blank" class="keylink">vcD4KPHA+PGJyPgo8L3A+CjxwPjxpbWcgc3JjPQ=="/uploadfile/Collfiles/20140617/2014061708371888.jpg" alt="\">


第三步:申請provisioning profile,生成.mobileprovision,雙擊該證書才能正確導入手機設備,不能拖。


\

\


第四步:創建應用,使其名字一致。


\

第五步:寫代碼


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{

// Override point for customization after application launch.

// return YES;

UIRemoteNotificationType types =

(UIRemoteNotificationTypeBadge

"UIRemoteNotificationTypeSound

|UIRemoteNotificationTypeAlert);

//注冊消息推送

[[UIApplication sharedApplication]registerForRemoteNotificationTypes:types];

return YES;

}


//獲取DeviceToken成功

- (void)application:(UIApplication *)application

didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken

{

NSLog(@"DeviceToken: {%@}",deviceToken);

//這裡進行的操作,是將Device Token發送到服務端

UIAlertView * alert = [[UIAlertView alloc]initWithTitle:nil message:[NSString stringWithFormat:@"DeviceToken:%@",deviceToken] delegate:self cancelButtonTitle:nil otherButtonTitles:@"確定", nil];

[alert show];

}


//注冊消息推送失敗

- (void)application:(UIApplication *)application

didFailToRegisterForRemoteNotificationsWithError:(NSError *)error

{

NSLog(@"Register Remote Notifications error:{%@}",error);

// NSLog(@"Register Remote Notifications error:{%@}",error.localizedDescription);

}


//處理收到的消息推送

- (void)application:(UIApplication *)application

didReceiveRemoteNotification:(NSDictionary *)userInfo

{

NSLog(@"Receive remote notification : %@",userInfo);

UIAlertView *alert =

[[UIAlertView alloc] initWithTitle:@"溫馨提示"

message:@"推送成功!"

delegate:nil

cancelButtonTitle:@"確定"

otherButtonTitles:nil];

[alert show];

}



  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved