/**
* 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