Coder Social home page Coder Social logo

xdworktime's Introduction

XDWorkTime

排列上班时间表

应用下载

排班APP下载地址或者扫下面二维码下载

image

由于是企业级证书打包发布,iOS9需要去设置-通用-设备管理里面手动信任打包应用的证书

功能介绍

一个工具类小应用。

提供给轮班上班的人们,上班时间不按照周一至周五工作日,周六日休息,有可能两天白班两天夜班三天晚班然后休息两天,然后再循环。周而复始一如既往,不管周六日,哪管黄金周。

还掺杂了其他小功能,天气预报、笑话大全、影讯,调用了聚合数据提供的接口。

还有注册、登录、记录事项等功能,使用了Bmob后端服务

适配iOS10,添加了窗口小部件widget

首页 widget
image img

窗口小部件widget的开发

widget是iOS8时推出的窗口小部件功能,窗口小部件在Android上早已大行其道。记得当年用过的第一部Android机是深圳出产的国产机佳域,当时划过三四个屏幕的应用,还能继续划过三四个屏幕的窗口小部件。用的最多的窗口小部件就是日历了,屏幕上一目了然。

Apple直到iOS8才加入窗口小部件,而且可自定义程度远远没有Android开放。

创建widget

widget可以理解为一个独立的项目,虽然形式上看来像是附属于app的一部分功能,其实并不是,widget想获取app的数据,还需要做数据共享。

File -> New -> Target

img

选择iOS里的Today Extension

img

习惯使用纯代码布局,喜欢用storyboard的略过。在新创建的widget项目文件夹中删除MainInterface.storyboard,修改info.plist如下内容

img

确定将原来的key-value:NSExtensionMainStoryboard MainInterface修改为NSExtensionPrincipalClass TodayViewControllerTodayViewController是自定义的控制器名字。

widget折叠

iOS10之后才有的widget折叠。

#ifdef __IPHONE_10_0
    //需要折叠
    self.extensionContext.widgetLargestAvailableDisplayMode = NCWidgetDisplayModeExpanded;
#endif

实现下面方法。

- (void)widgetActiveDisplayModeDidChange:(NCWidgetDisplayMode)activeDisplayMode withMaximumSize:(CGSize)maxSize {
    if (activeDisplayMode == NCWidgetDisplayModeCompact) {
        self.preferredContentSize = CGSizeMake([UIScreen mainScreen].bounds.size.width, 100);
    } else {
        self.preferredContentSize = CGSizeMake([UIScreen mainScreen].bounds.size.width, 400);
    }
}

点击widget开启app

在app的TARGEST里的infoURL Types添加URL Schemes

img

widget上显示的自定义view:_calendarView,给_calendarView添加触摸事件。

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(openApp)];
[_calendarView addGestureRecognizer:tap];

实现触摸事件,开启app

- (void)openApp {
    [self.extensionContext openURL:[NSURL URLWithString:@"paibanapp://"] completionHandler:^(BOOL success) {
        NSLog(@"successs = %d", success);
    }];
}

数据共享

创建App Groups的Identifiers。在创建证书的时候勾选App Groups,设置创建的App Groups

img

在Xcode的TARGEST -> Capabilities里打开App Groups。

img

用NSUserDefaults共享数据,

存储数据

NSUserDefaults *shared = [[NSUserDefaults alloc] initWithSuiteName:@"group.xxxx"];//App Groups ID
[shared setObject:[NSDictionary dictionaryWithObjectsAndKeys:dutyArray, @"dutyArrayKey", selectDayStr, @"selectDayStrKey", tags, @"selectTagArrayKey", nil] forKey:@"todayViewShared"];
[shared synchronize];

读取数据

NSUserDefaults *shared = [[NSUserDefaults alloc] initWithSuiteName:@"group.xxxx"];//App Groups ID
NSDictionary *dict = [NSDictionary dictionaryWithDictionary:[shared objectForKey:@"todayViewShared"]];

用NSFileManager共享数据

存储数据

NSError *err = nil;
NSURL *containerURL = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:@"group.xxxx"];//App Groups ID
containerURL = [containerURL URLByAppendingPathComponent:@"Library/Caches/widget"];
NSDictionary *value = [NSDictionary dictionaryWithObjectsAndKeys:dutyArray, @"dutyArrayKey", selectDayStr, @"selectDayStrKey", tags, @"selectTagArrayKey", nil];
BOOL result = [value writeToURL:containerURL atomically:YES encoding:NSUTF8StringEncoding error:&err];
if (!result) {
	NSLog(@"%@",err);
} else {
	NSLog(@"save value:%@ success.",value);
}

读取数据

NSError *err = nil;
NSURL *containerURL = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:@"group.xxxx"];//App Groups ID
containerURL = [containerURL URLByAppendingPathComponent:@"Library/Caches/widget"];
NSString *value = [NSString stringWithContentsOfURL:containerURL encoding: NSUTF8StringEncoding error:&err];

xdworktime's People

Contributors

mxdios avatar

Stargazers

John.Chang avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.