iOS 推送 擷取手機裝置的 deviceToken

來源:互聯網
上載者:User

標籤:out   tle   use   .net   type   sda   cancel   art   otto   


第一步:申請認證:




第二步:申請app ids,應用程式名稱字必須一致。然後再進入進行編輯。使其enable,綠燈。




第三步:申請provisioning profile,產生.mobileprovision,雙擊該認證才幹正確匯入手機裝置。不能拖。





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



第五步:寫代碼


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

{

    // Override point for customization after application launch.

//    return YES;

    UIRemoteNotificationType types =

    (UIRemoteNotificationTypeBadge

     |UIRemoteNotificationTypeSound

     |UIRemoteNotificationTypeAlert);

    

    //注冊訊息推送

    [[UIApplicationsharedApplication]registerForRemoteNotificationTypes:types];

    return YES;

    

}


//擷取DeviceToken成功

- (void)application:(UIApplication *)application

didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken

{

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

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

    

    UIAlertView * alert = [[UIAlertViewalloc]initWithTitle:nilmessage:[NSStringstringWithFormat:@"DeviceToken:%@",deviceToken]delegate:selfcancelButtonTitle:nilotherButtonTitles:@"確定",nil];

    [alertshow];

}


//注冊訊息推送失敗

- (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 =

    [[UIAlertViewalloc] initWithTitle:@"溫馨提示"

                              message:@"推送成功。"

                             delegate:nil

                    cancelButtonTitle:@"確定"

                    otherButtonTitles:nil];

    [alertshow];

}



iOS 推送 擷取手機裝置的 deviceToken

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.