Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3430199
  • 博文数量: 864
  • 博客积分: 14125
  • 博客等级: 上将
  • 技术积分: 10634
  • 用 户 组: 普通用户
  • 注册时间: 2007-07-27 16:53
个人简介

https://github.com/zytc2009/BigTeam_learning

文章分类

全部博文(864)

文章存档

2023年(1)

2021年(1)

2019年(3)

2018年(1)

2017年(10)

2015年(3)

2014年(8)

2013年(3)

2012年(69)

2011年(103)

2010年(357)

2009年(283)

2008年(22)

分类: 嵌入式

2012-10-30 12:44:07

7.类型、描述和词汇:
id – 动态对象类型。动态类型和静态类型对象的否定词汇为 nil。
Class – 动态类的类型。它的否定词汇为 Nil。
SEL – 选择器的数据类型(typedef);这种数据类型代表运行时的一种签名方法。它的否定词汇为 NULL。
BOOL – 布尔型。代表它的值的词汇为 YES 和 NO。


8.weak,Strong
  弱引用:一旦对象不再有强引用,运行时就会从释放该对象,即使还有weak型指针指向它
  在以下这几类引用中,你应该使用弱引用:
   (1)委托
       在《设计模式》篇里,“用设计模式让应用开发流水线化”教程将向你详解委托和目标机制。

   (2)未被顶级对象引用的插座变量(Outlet)
      插座变量是对象间的一种连接(或引用),被归档在故事版文件或 nib 文件中,当应用运行并载入故事版或 nib 文件时就会恢复插座变量。故事版或 nib 文件中顶级对象的插座变量一般而言是窗口、视图、视图控制器或其他控制器等,应该为 强引用(默认的,或未标记的)。

   (3)目标

   (4)块对象中指向 self 的引用
    块对象会对它捕获的变量产生强引用。如果你在块对象里使用了 self,则会对 self 产生强引用。所以,如果 self 对块对象也有强引用(通常都会这样),就形成了强引用死循环。为了避免死循环,你需要在块对象的外面创建一个指向 self 的 弱(或 __block)引用,


9.探究对象是否是某个类或其子类的实例
   isMemberOfClass: 方法会告诉你对象是否是某个指定类的实例,而 isKindOfClass: 会告诉你对象是否是某个类或其子类的成员。
  for (id item in myArray) {
    if ([item isKindOfClass:[NSNumber class]]) {
        int i = (int)[item intValue];
        sum += i;
    }
  }


10.探究对象是否能够响应某个消息
  respondsToSelector: 方法需要一个选择器作为参数。选择器是 Objective-C 的一个数据类型,可以在运行时标识某个方法;利用 @selector 编译器指令可以指定该选择器。
   
  if ([item respondsToSelector:@selector(setState:)]) {
    [item setState:[self.arcView.font isBold] ? NSOnState : NSOffState];
  }


11.探究对象是否遵守某个协议
  conformsToProtocol: 方法需要协议的运行时标识符作为参数;利用 @protocol 编译器指令可以指定此标识符。
 
  - (void) setDelegate:(id __weak) obj {
    NSParameterAssert([obj conformsToProtocol:
        @protocol(SubviewTableViewControllerDataSourceProtocol)]);
    delegate = obj;
  }

12.工程架构:
    logo: logo标识
    default: 默认页面的启动效果
    image:存放图片
    n个UIViewController:
    AppDelegate : start category module

13.XMPP安全连接

[xmppStream connect:&error]
[xmppStream setHostPort:5222];
allowSelfSignedCertificates = NO;
allowSSLHostNameMismatch = NO;
       
[xmppStream oldSchoolSecureConnect:&error]
[xmppStream setHostPort:5223];
allowSelfSignedCertificates = YES;
allowSSLHostNameMismatch = YES;


14.应用后台运行
 Go to your info.plist

Add the key 'Required background modes' and set the value to 'App plays audio' 或者 'App provides Voice over IP services'
Add the key 'Application does not run in background' and set the value to 'YES'


15.实现锁屏后继续播放音乐的问题  
   (1).设置分类,必须是 AVAudioSessionCategoryPlayback
   [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: nil];

  (2).设置策略
      UInt32 doSetProperty = true;
    //The C Style function call
    AudioSessionSetProperty (
                             kAudioSessionProperty_OverrideCategoryMixWithOthers,
                             sizeof (doSetProperty),
                             &doSetProperty
                             );

  (3).为你的应用增加UIBackgroundModes属性, 选中 Info.plist文件添加,然后选择audio相关项

  (4).修改你的applicationDidEnterBackground方法:
   //得到当前应用程序的UIApplication对象
    UIApplication *app = [UIApplication sharedApplication];
  
    //一个后台任务标识符
    UIBackgroundTaskIdentifier taskID;
    taskID = [app beginBackgroundTaskWithExpirationHandler:^{
        //如果系统觉得我们还是运行了太久,将执行这个程序块,并停止运行应用程序
        [app endBackgroundTask:taskID];
    }];
    //UIBackgroundTaskInvalid表示系统没有为我们提供额外的时候
    if (taskID == UIBackgroundTaskInvalid) {
        NSLog(@"Failed to start background task!");
        return;
    }

   对于VOIP应用,也要有以下的两步,当然还需要后台工作的socket和你的keepAlive机制:
     1.为你的应用增加UIBackgroundModes属性, 选中 Info.plist文件添加,然后选择voip相关项
     2.同上(4).


16. 自定义对象写文件,需要实现NSCoding协议的两个接口
 // name,addr为两个NSString数据
- (void)encodeWithCoder:(NSCoder *)encoder{
    [encoder encodeObject:self.name forKey:@"name"];
    [encoder encodeObject:self.addr forKey:@"addr"];
}

- (id)initWithCoder:(NSCoder *)decoder{
    self = [super init];
    self.name = [decoder decodeObjectForKey:@"name"];
    self.addr = [decoder decodeObjectForKey:@"addr"];
    return self;
}

 //read file
     NSString *personFile = [myfolder stringByAppendingPathComponent:@"person.txt"];
    if([fm fileExistsAtPath:personFile])
    {
        NSData *personData= [[NSData alloc]initWithContentsOfFile:personFile];
        Person *person = [NSKeyedUnarchiver unarchiveObjectWithData:personData];
        [self NameText].text = person.name;
        [self AddrText].text = person.addr;
    }

 //save data to file
- (IBAction)SaveText:(id)sender {

    Person *person = [[Person alloc]init];
    person.name = [NameText text];
    person.addr = [AddrText text];
    
  //转化为NSData
    NSData * personData = [NSKeyedArchiver archivedDataWithRootObject:person];
    NSString *personFile = [myfolder stringByAppendingPathComponent:@"person.txt"];
    [personData writeToFile:personFile atomically:NO];
    
}
阅读(1775) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~