首页 文章 精选 留言 我的

精选列表

搜索[ios],共10000篇文章
优秀的个人博客,低调大师

iOS开发 落地消息多的处理办法(仅供参考)

1.首先要知道一点,你的消息储存是用数据库储存的! 看了一下微信和qq的消息处理,一般情况下第三方(亲加,容云,环信都会有本地的数据库)处理过的! 但是我发现,最近一个需求要求开发@”消息已读“@”消息送达“的处理,和UI显示。 我想了各种办法,GCD线程异步,带来的会有另外的一个问题,多线程访问同一个资源,be locked。或者说你在接收到消息的时候开一个线程,接到消息的时候开一个线程。一般情况下是没有问题的。但是重新一个账号登陆的时候就会有以前你读过和没有读过的消息!(如果你们购买了,app和网页消息同步的时候)! 解决办法: 后台开一个永驻线程(有崩溃主线程中也不受到影响),而且也不会多个线程访问同一个路径下的数据库 @property (nonatomic, strong) NSThread *thread; /***开启一个永驻线程**/ - (void)threadRunloopPoint:(id)__unused object{ NSLog(@"%@",NSStringFromSelector(_cmd)); @autoreleasepool { [[NSThread currentThread] setName:@"changzhuThread"]; NSRunLoop *runLoop = [NSRunLoop currentRunLoop]; //// 这里主要是监听某个 port,目的是让这个 Thread 不会回收 [runLoop addPort:[NSMachPort port] forMode:NSDefaultRunLoopMode]; [runLoop run]; } } - (NSThread *)thread{ if(!_thread){ _thread = [[NSThread alloc] initWithTarget:self selector:@selector(threadRunloopPoint:) object:nil]; [_thread start]; } return _thread; } //接收到已读消息回执的代理 - (void)NotificationCenterReadMessage:(NSNotification *)notification{ ReadMessageTime * readMark = [[ReadMessageTime alloc]init];//已读回执消息对象(自己建立) readMark.cType = [notification.userInfo objectForKey:@"cType"]; readMark.messageTime = [notification.userInfo objectForKey:@"messageTime"]; readMark.tId = [notification.userInfo objectForKey:@"tId"]; [self performSelector:@selector(insertReadMessageTime:) onThread:self.thread withObject:readMark waitUntilDone:NO modes:@[NSDefaultRunLoopMode]]; } - (void)insertReadMessageTime:(id)readMark{ [[[MyFMDB alloc]init] insertReadMessageTime:readMark]; }

优秀的个人博客,低调大师

[iOS]原生swift的hotpatch可行性初探 续1

0x0 引子 之前在<原生swift的hotpatch可行性初探>对swift hotpatch的原理做一个简单的介绍和简单的示例, 但基础的原理分析并不能确定真实的可行性. 为此想通过这篇文章来做一个更复杂的例子. 0x1 先来一个简单的例子 来一个例子, 实现用js patch swift的方法, 功能包括: 在js中通过类名/方法名/替换的方法, 来替换swift的方法 在js中通过方法名来调用原有的swift方法 swift代码: public class ViewController: UIViewController { override public func viewDidLoad() { super.viewDidLoad() patch_init()

优秀的个人博客,低调大师

iOS开发 - Content hugging priority & Content compression resistance prio...

1. 什么是Content hugging priority 你可以把它想象成一根放在视图上的橡皮筋。 这根橡皮筋会组织视图超过它本身的固有大小(intrinsic content size)。 它存在一个优先级,从0到1000。 1000表示视图绝对不能超过intrinsic content size。 我们来看个例子: 上图中有两个横向排列的标签控件(label),并且你也已经设置好了约束。 这个会工作正常,直到父视图变宽的时候。 那么,问题来了。 如果父视图变宽了,那个label应该变宽呢? 这个时候正是我们用到Content hugging priority的时候。 拥有高优先级Content hugging priority的视图控件将不会被拉伸。 你可以把这个优先级想象成橡皮筋的抗拉伸力。 这个优先级越大,视图将越希望保持自己的固有大小(intrinsic content size)。 2.Content compression resistance priority 和Content hugging priority相反,Content compression resistance priority是用来抵抗压缩的。 简单的来说,前者我们讨论过的,是抵抗拉伸,也就是抵抗变大,而后者是抵抗压缩,也就是抵抗变小。 还是上面的例子中,当父视图变小的时候,拥有高优先级的label将不会被压缩,因而标签上的文本也就不会被截断。

优秀的个人博客,低调大师

iOS开发技巧 - 使用UIDatePicker来选择日期和时间

(Swift) import UIKit class ViewController: UIViewController { var datePicker: UIDatePicker! func datePickerDateChanged(datePicker: UIDatePicker) { println("Selected date = \(datePicker.date)") } override func viewDidLoad() { super.viewDidLoad() datePicker = UIDatePicker() datePicker.center = view.center view.addSubview(datePicker) datePicker.addTarget(self, action: "datePickerDateChanged:", forControlEvents: .ValueChanged) /* set the minimum and the maximum dates that it can display */ let oneYearTime:NSTimeInterval = 365 * 24 * 60 * 60 let todayDate = NSDate() let oneYearFromToday = todayDate.dateByAddingTimeInterval(oneYearTime) let twoYearsFromToday = todayDate.dateByAddingTimeInterval(2 * oneYearTime) datePicker.minimumDate = oneYearFromToday datePicker.maximumDate = twoYearsFromToday } } (Objective-C) #import "ViewController.h" @interface ViewController () @property (nonatomic, strong) UIDatePicker *myDatePicker; @end @implementation ViewController - (void) datePickerDateChanged:(UIDatePicker *)paramDatePicker { if ([paramDatePicker isEqual:self.myDatePicker]) { NSLog(@"Selected date = %@", paramDatePicker.date); } } - (void)viewDidLoad { [super viewDidLoad]; self.myDatePicker = [[UIDatePicker alloc] init]; self.myDatePicker.center = self.view.center; [self.view addSubview:self.myDatePicker]; [self.myDatePicker addTarget:self action:@selector(datePickerDateChanged:) forControlEvents:UIControlEventValueChanged]; NSTimeInterval oneYearTime = 365 * 24 * 60 * 60; NSDate *todayDate = [NSDate date]; NSDate *oneYearFromToday = [todayDate dateByAddingTimeInterval:oneYearTime]; NSDate *twoYearsFromToday = [todayDate dateByAddingTimeInterval:2 * oneYearTime]; self.myDatePicker.minimumDate = oneYearFromToday; self.myDatePicker.maximumDate = twoYearsFromToday; } @end

优秀的个人博客,低调大师

iOS开发技巧 - 使用Alerts和Action Sheets显示弹出框

解决方案: (Swift) 使用UIAlertController类 (Objective-C) 使用UIAlertView类 代码: (Swift) import UIKit class ViewController: UIViewController { // 1. define the variable that will hold our alert controller var controller:UIAlertController? override func viewDidLoad() { super.viewDidLoad() // 2. start constructing a simple alert view controller using the alert view style controller = UIAlertController(title: "Title", message: "Message", preferredStyle: .Alert) // 3. simply print out a text to the console when pressed let action = UIAlertAction(title: "Done", style: UIAlertActionStyle.Default, handler: { (paramAction:UIAlertAction!) in println("The Done button was tapped") }) // 4. add the action that we created to the alert controller controller!.addAction(action) } override func viewDidAppear(animated: Bool) { super.viewDidAppear(animated) // 5. present the alert controller self.presentViewController(controller!, animated: true, completion: nil) } } (Objective-C) #import "ViewController.h" @interface ViewController () <UIAlertViewDelegate> @end @implementation ViewController ... - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; self.view.backgroundColor = [UIColor whiteColor]; NSString *message = @"Are you sure you want to open this link in Safari?"; UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Open Link" message:message delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil]; [alertView show]; } - (void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { NSString *buttonTitle = [alertView buttonTitleAtIndex:buttonIndex]; if ([buttonTitle isEqualToString:@"Yes"]){ NSLog(@"User pressed the Yes button."); } else if ([buttonTitle isEqualToString:@"No"]){ NSLog(@"User pressed the No button."); } }

资源下载

更多资源
优质分享App

优质分享App

近一个月的开发和优化,本站点的第一个app全新上线。该app采用极致压缩,本体才4.36MB。系统里面做了大量数据访问、缓存优化。方便用户在手机上查看文章。后续会推出HarmonyOS的适配版本。

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

用户登录
用户注册
修改密码
忘记密码