有用的代码

分享2个宏,放到pch文件里面,你懂的

//use dlog to print while in debug model
#ifdef DEBUG
# define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
#else
# define DLog(...)
#endif

//another one
#if DEBUG
#define NSLog(FORMAT, ...) fprintf(stderr,"%s:%d\t%s\n",[[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__, [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);
#else
#define NSLog(FORMAT, ...) nil

#endif




后台下载,发出来给大家参考参考,貌似这样只能下10分钟

//crespo add 1101
- (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.
  
  //crespo add 1109 to close broadcast when enter background
  if (onlookerUDP)
  {
    [self stopAndClearTimer];
    [onlookerUDP release];
    onlookerUDP = nil;
  }
  
  //crespo add 1031 for back fground download
  UIDevice* device = [UIDevice currentDevice];
  BOOL backgroundSupported = NO;
  if ([device respondsToSelector:@selector(isMultitaskingSupported)])
  {
    backgroundSupported = device.multitaskingSupported;
  }
  if (backgroundSupported == YES)
  {
    //crespo add 1108
    if ([[self GetCurrntNet]isEqualToString:@"3g"])
    {
      NSUserDefaults* userDefault = [NSUserDefaults standardUserDefaults];
      if ([userDefault boolForKey:@"3gBackgroudDownload"] == NO)
      {
        return;
      }
    }

    
    __block UIBackgroundTaskIdentifier bgTask;
    bgTask = [application beginBackgroundTaskWithExpirationHandler:^{
      // Clean up any unfinished task business by marking where you.
      // stopped or ending the task outright.
      //如果系统觉得我们还是运行了太久,将执行这个程序块,并停止运行应用程序
      for (int i = 0; i < [TCDownloadManager sharedManager].tasks.count; i++)
      {
        TCDownloadTaskVideo* t = [[TCDownloadManager sharedManager].tasks objectAtIndex:i];
        if (t.status == DownloadTaskStatusDownloading)
        {
          //stop downloading
          DLog(@"stop downloading after 10 minutes later!");
          [t cancel];
        }
      }
      [application endBackgroundTask:bgTask];
      bgTask = UIBackgroundTaskInvalid;
    }];
    
    //UIBackgroundTaskInvalid表示系统没有为我们提供额外的时候
    if (bgTask == UIBackgroundTaskInvalid) {
      DLog(@"Failed to start background task!");
      return;
    }
    
    // Start the long-running task and return immediately.
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
      
      // Do the work associated with the task, preferably in chunks.
      //do not use NSEnumerator,has bug
//      for (TCDownloadTaskVideo* t in [TCDownloadManager sharedManager].tasks)
//      {
//        ...
//      }
      
      for (int i = 0; i < [TCDownloadManager sharedManager].tasks.count; i++)
      {
        TCDownloadTaskVideo* t = [[TCDownloadManager sharedManager].tasks objectAtIndex:i];
        if (t.status == DownloadTaskStatusDownloading)
        {
          //keep on downloading
          DLog(@"start background task for downloading!");
          [t cancel];
          [[TCDownloadManager sharedManager]restartTask:t];
        }
      }
       // 任务做完以后通过下面的代码通知系统该任务结束了
      //[application endBackgroundTask:bgTask];
      //bgTask = UIBackgroundTaskInvalid;
    });
  }
  
}

刚刚有的同学问我,同时录音和播放就没声音了,以下是我在stackoverflow找到的方法,我用过可以的,如果有别的欢迎补充:
        if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone || UIUserInterfaceIdiomPad)
        {
            AVAudioSession *audioSession = [AVAudioSession sharedInstance];
            NSError *error;
            if ([audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:&error])
            {
                if ([audioSession setActive:YES error:&error])
                {
                    //        AudioServicesPlaySystemSound (kSystemSoundID_Vibrate);
                }
                else
                {
                    NSLog(@"Failed to set audio session category: %@", error);
                }
            }
            else
            {
                NSLog(@"Failed to set audio session category: %@", error);
            }
            UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
            AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,sizeof(audioRouteOverride),&audioRouteOverride);

        }


ios持续震动&解决震动后电影/音乐无声音bug的方法

持续震动代码:
#import < AudioToolbox/AudioToolbox.h>
#import < UIKit/UIKit.h>


void MyAudioServicesSystemSoundCompletionProc (SystemSoundID ssID,void *clientData)
{
BOOL* iShouldKeepBuzzing = clientData;
if (*iShouldKeepBuzzing)
{
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
}
else
{
//Unregister, so we don't get called again...
AudioServicesRemoveSystemSoundCompletion(kSystemSoundID_Vibrate);
}
}

-(void)infinityVibrate
{
BOOL iShouldKeepBuzzing = YES;
AudioServicesAddSystemSoundCompletion (
kSystemSoundID_Vibrate,
NULL,
NULL,
MyAudioServicesSystemSoundCompletionProc,
&iShouldKeepBuzzing );
AudioServicesPlaySystemSound (kSystemSoundID_Vibrate);
}

这么调用就行了撒:[self infinityVibrate];

播放电影的时候震动,电影无声音,解决办法:
//add by crespo to fix a bug ,when start to play movie vibrate won't disable the movie voice
AudioSessionInitialize(NULL, NULL, NULL, NULL);
UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback;
AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof (sessionCategory), &sessionCategory);


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Excel宏是一种自动化工具,它可以帮助我们自动执行一些繁琐的操作或者完成一些复杂的任务。以下是一些常用的、有用的Excel宏代码示例: 1. 去重复值:使用宏代码可以快速去除Excel表格中的重复值,提高数据的整洁性和准确性。 2. 自动筛选数据:通过编写宏代码,我们可以创建一个自动筛选数据的功能,根据特定的条件筛选出符合要求的数据。 3. 合并单元格:Excel宏代码可以实现将多个单元格合并成一个单元格,方便美化表格和展示数据。 4. 条件格式化:宏代码可以根据一定的条件自动对单元格进行格式化,比如根据数值大小、文本内容等进行颜色填充、字体加粗等操作。 5. 数据分析:宏代码可以帮助我们自动进行数据分析,比如自动生成图表、计算平均值、求和等统计功能。 6. 批量操作:通过宏代码,我们可以批量执行某些操作,比如批量修改特定单元格的数值、批量重命名工作表等。 7. 数据导入导出:利用宏代码,我们可以实现将数据从Excel导出到其他软件或系统,或者从其他软件或系统导入到Excel中。 8. 自动填充:宏代码可以自动填充连续的数据,比如日期、序列等,提高工作效率。 9. 定时任务:通过宏代码,我们可以设置定时任务,自动执行某些操作,比如每天定时备份数据、自动保存文件等。 总之,Excel宏代码是一个非常强大的工具,可以帮助我们简化工作流程,提高工作效率。但需要注意的是,编写宏代码需要一定的编程知识和经验,确保代码的正确性和安全性。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值