backgroundtask

 req.networkServiceType = NSURLNetworkServiceTypeVoIP;

https://github.com/sinch/ios-pushkit-tutorial/tree/aeebc397a6644af00d672bbf4a292951ffb29c9e

https://github.com/search?l=objective-c&q=PKPushRegistry&type=Code&utf8=%E2%9C%93

 

http://www.2cto.com/kf/201312/261962.html

 

1、NSInputStream 和NSOutputStream 对于 Cocoa streams, 使用 setProperty:forKey: 方法添加 
NSStreamNetworkServiceType 属性给 stream. 改属性的值设为 NSStreamNetworkServiceTypeVoIP. 
2、NSURLRequest 对于 URL loading system, 使用 setNetworkServiceType: method of your NSMutableURLRequest object to set the network service 
type of the request. The service type should be set to NSURLNetworkServiceTypeVoIP. 
3、CFReadStreamRef和CFWriteStreamRef For Core Foundation streams, use the CFReadStreamSetProperty or CFWriteStreamSetProperty function to add the kCFStreamNetwork- ServiceType property to the stream. The value for this property should be set to kCFStreamNetworkServiceTypeVoIP. (注意:当设置socket的时候,你需要在你的主信号通道中设置合适的service type key。当设置声道时,不需要设置这个key) 

 

https://github.com/qiruihua/dongdongwang

 

    UIBackgroundTaskIdentifier backgroundTaskIdentifier;

    UIBackgroundTaskIdentifier oldBackgroundTaskIdentifier;

@property(nonatomic,retain)NSTimer *myTimer;;

 

- (void) timerMethod:(NSTimer *)paramSender{

    count++;

    NSLog(@"count = %ds",count);

    if (count % 500 == 0) {

        NSLog(@"start new task:at %ds",count);

        UIApplication *application = [UIApplication sharedApplication];

        //开启一个新的后台

        backgroundTaskIdentifier = [application beginBackgroundTaskWithExpirationHandler:^{

        }];

        //结束旧的后台任务

        [application endBackgroundTask:backgroundTaskIdentifier];

        oldBackgroundTaskIdentifier = backgroundTaskIdentifier;

    }

    // NSLog(@"%d",count);

}

 

- (void)applicationDidEnterBackground:(UIApplication *)application

{

    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 

    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.

    

    isEnterForground = NO;

    

    

    if ([self isMultitaskingSupported] == NO){

        

        return; }

    //开启一个后台任务

    

    backgroundTaskIdentifier = [application beginBackgroundTaskWithExpirationHandler:^{

    }];

    oldBackgroundTaskIdentifier = backgroundTaskIdentifier;

    if ([self.myTimer isValid]) {

        [self.myTimer invalidate];

    }

    count=0;

    self.myTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timerMethod:) userInfo:nil repeats:YES];

}

 

posted @ 2016-05-19 21:50  lianhuaren  阅读(85)  评论(0)    收藏  举报