iOS Development-Bluetooth backend receive data (BLE4.0)

Source: Internet
Author: User
Tags set time

1. In the Xxx-info.plist file, create a new row Required background modes , adding the following two items.

app shares data using Corebluetooth and app communicates using Corebluetooth

:



After adding this entry, you will find that Bluetooth remains connected when the app is in the background.

However, after entering the background, although the application is still hanging, can receive data normally. However, to the data, if we need to respond in real time, it will be used to push.

That is, when the data comes, pop up a prompt box, prompting the user to come to the data.


2. Set up local push

The method here is written in APPDELEGATE.M. The receivedata corresponds to the response function that you receive the data.

[CPP] view plaincopy

  1. -(void) Receivedata: (nsdata*) Data

  2. {

  3. NSLog (@"received data");

  4. //Receive data, set push   

  5. Uilocalnotification *noti = [[Uilocalnotification alloc] init];

  6. if (Noti)

  7. {

  8. //Set time zone   

  9. Noti.timezone = [Nstimezone defaulttimezone];

  10. //Set repeat Interval   

  11. Noti.repeatinterval = Nsweekcalendarunit;

  12. //Push sound   

  13. Noti.soundname = Uilocalnotificationdefaultsoundname;

  14. //Content   

  15. Noti.alertbody = @"received data";

  16. Noti.alertaction = @"open";

  17. //The number of the red circle displayed on the icon   

  18. Noti.applicationiconbadgenumber = 1;

  19. //Set UserInfo to be used after subsequent revocation   

  20. Nsdictionary *infodic = [nsdictionary dictionarywithobject:@"name" forkey:@"key"];

  21. Noti.userinfo = Infodic;

  22. //Add push to UIApplication   

  23. UIApplication *app = [UIApplication sharedapplication];

  24. [App Schedulelocalnotification:noti];

  25. }

  26. }


[CPP] view plaincopy

  1. #pragma mark-received a push

  2. -(void) Application: (UIApplication *) application didreceivelocalnotification: (uilocalnotification*) Notification

  3. {

  4. Uialertview *alert = [[Uialertview alloc] initwithtitle:@"Call Prompt"

  5. Message:notification.alertBody

  6. Delegate:nil

  7. cancelbuttontitle:@"Answer"

  8. otherbuttontitles:@"Hang Off", nil];

  9. [Alert show];

  10. //Here, you can do something you want to do through notification's Useinfo .

  11. Application.applicationiconbadgenumber-= 1;

  12. }


iOS Development-Bluetooth backend receive data (BLE4.0)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.