1014-31-Home 12-show Weibo unread--run---timer in the background

Source: Internet
Author: User

/**
* Called when the app enters the background
*/
-(void) Applicationdidenterbackground: (uiapplication *) application
{
/**
* Status of App
* 1. Death Status: No app opened
* 2. Foreground operation status
* 3. Background suspend state: Stop all animations, timers, multimedia, networking operations, it is difficult to do other operations
* 4. Background running status
*/
Eligibility to apply for background runs to the operating system,It's not sure how long it will last .
Uibackgroundtaskidentifier task = [Application beginbackgroundtaskwithexpirationhandler:^{
When the background run time for the application has ended (expired), the block is called

Finish the mission.
[Application Endbackgroundtask:task];
}];

Setting the background mode in Info.plist: Required background modes = = APP plays audio or streams audio/video using AirPlay
Engage in a 0kb MP3 file with no sound
Loop playback

There are only 3 types of previous background modes
Keep your network connected
Multimedia applications
VOIP: Internet telephony
}

----------------------------------------------------------------------------------------------------

-(void) test {

Get no readings
Nstimer *timer = [nstimer scheduledtimerwithtimeinterval:60 target:self selector: @selector ( Setupunreadcount) Userinfo:nil Repeats:yes];
The main thread also takes time to process the timer (regardless of whether the main thread is in another event)
[[Nsrunloop Mainrunloop] Addtimer:timer formode:nsrunloopcommonmodes];

}


/**
* Get no readings
*/
-(void)Setupunreadcount
{
Hwlog (@ "Setupunreadcount");
Return
1. Request the manager
Afhttprequestoperationmanager *mgr = [Afhttprequestoperationmanager manager];

2. Stitching Request Parameters
Hwaccount *account = [Hwaccounttool account];
Nsmutabledictionary *params = [Nsmutabledictionary dictionary];
params[@ "Access_token"] = Account.access_token;
params[@ "UID"] = Account.uid;

3. Sending the request
[Mgr get:@ "Https://rm.api.weibo.com/2/remind/unread_count.json" Parameters:params success:^ ( Afhttprequestoperation *operation, Nsdictionary *responseobject) {
Non-reading of Weibo
int status = [responseobject[@ "status"] intvalue];
Set Reminder numbers
Self.tabBarItem.badgeValue = [NSString stringwithformat:@ "%d", status];

@20-@ "20"
NSNumber-NSString
Set reminder numbers (unread on Weibo)
NSString *status = [responseobject[@ "status"] description];//Use description to convert NSNumber to string object easily
if ([Status isequaltostring:@ "0"]) {//If 0, the number must be emptied
Self.tabBarItem.badgeValue = nil;
[UIApplication sharedapplication].applicationiconbadgenumber = 0;
} else {//Non 0 case
Self.tabBarItem.badgeValue = status;
[UIApplication sharedapplication].applicationiconbadgenumber = Status.intvalue;
}
} failure:^ (Afhttprequestoperation *operation, Nserror *error) {
Hwlog (@ "request failed-%@", error);
}];
}

----------------------------------------------------------------------------------------------------

1014-31-Home 12-show Weibo unread--run---timer in the background

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.