标签:
#import "AppDelegate.h"
#import "UMessage.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[UMessage startWithAppkey:@"55f12b92e0f55a787b002451" launchOptions:launchOptions];
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= _IPHONE80_
//register remoteNotification types (iOS 8.0及其以上版本)
UIMutableUserNotificationAction *action1 = [[UIMutableUserNotificationAction alloc] init];
action1.identifier = @"action1_identifier";
action1.title=@"Accept";
action1.activationMode = UIUserNotificationActivationModeForeground;//当点击的时候启动程序
UIMutableUserNotificationAction *action2 = [[UIMutableUserNotificationAction alloc] init]; //第二按钮
action2.identifier = @"action2_identifier";
action2.title=@"Reject";
action2.activationMode = UIUserNotificationActivationModeBackground;//当点击的时候不启动程序,在后台处理
action2.authenticationRequired = YES;//需要解锁才能处理,如果action.activationMode = UIUserNotificationActivationModeForeground;则这个属性被忽略;
action2.destructive = YES;
UIMutableUserNotificationCategory *categorys = [[UIMutableUserNotificationCategory alloc] init];
categorys.identifier = @"category1";//这组动作的唯一标示
[categorys setActions:@[action1,action2] forContext:(UIUserNotificationActionContextDefault)];
UIUserNotificationSettings *userSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge|UIUserNotificationTypeSound|UIUserNotificationTypeAlert
categories:[NSSet setWithObject:categorys]];
[UMessage registerRemoteNotificationAndUserNotificationSettings:userSettings];
#else
//register remoteNotification types (iOS 8.0以下)
[UMessage registerForRemoteNotificationTypes:UIRemoteNotificationTypeBadge
|UIRemoteNotificationTypeSound
|UIRemoteNotificationTypeAlert];
#endif
//for log
[UMessage setLogEnabled:YES];
return YES;
}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
[UMessage registerDeviceToken:deviceToken];
NSLog(@"%@",[[[[deviceToken description] stringByReplacingOccurrencesOfString: @"<" withString: @""]
stringByReplacingOccurrencesOfString: @">" withString: @""]
stringByReplacingOccurrencesOfString: @" " withString: @""]);
}
//
// DataApi.h
// nwkrnw
//
// Created by Dragon‘s Mac on 15/12/27.
// Copyright © 2015年 Dragon Mac. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "FMDB.h"
@interface DataApi : NSObject
@property(strong,nonatomic) FMDatabase* dataBase;
//单例
+(instancetype)sharedDataApi;
//插入
-(BOOL)insertDataToSzzWithName:(NSString*)name;
//get
-(NSArray* )getAllData;
@end
//
// DataApi.m
// nwkrnw
//
// Created by Dragon‘s Mac on 15/12/27.
// Copyright © 2015年 Dragon Mac. All rights reserved.
//
#import "DataApi.h"
@implementation DataApi
+(instancetype)sharedDataApi
{
static DataApi* dataApi;
static dispatch_once_t once;
dispatch_once(&once, ^{
dataApi = [[DataApi alloc] init];
dataApi.dataBase = [dataApi dataBase];
});
return dataApi;
}
-(FMDatabase *)dataBase
{
if (!_dataBase) {
_dataBase = [[FMDatabase alloc] initWithPath:[self documentPath]];
//打开数据库
[_dataBase open];
if ([self creataTable]) {
NSLog(@"数据库创建成功");
}
}
return _dataBase;
}
-(BOOL)insertDataToSzzWithName:(NSString *)name
{
if (![_dataBase open])
{
[_dataBase open];
}
NSString* sql = @"insert into szz (name) values (:name)";
NSDictionary* dic = @{@"name":name};
return [_dataBase executeUpdate:sql withParameterDictionary:dic];
}
-(NSArray *)getAllData
{
if (![_dataBase open]) {
[_dataBase open];
}
NSMutableArray* arr = [NSMutableArray new];
NSString* sql = @"select * from szz";
FMResultSet* result = [_dataBase executeQuery:sql];
while ([result next])
{
NSDictionary* dic = [NSDictionary dictionaryWithDictionary:[result resultDictionary]];
[arr addObject:dic];
}
return arr;
}
//创建数据表
-(BOOL )creataTable
{
NSString* sql = @"create table if not exists szz(id integer primary key autoincrement, name text)";
return [_dataBase executeUpdate:sql];
}
//
-(NSString* )documentPath
{
NSString* path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, 1)[0];
return [path stringByAppendingPathComponent:@"ssz.sqlite"];
}
@end
//
// ViewController.m
// nwkrnw
//
// Created by Dragon‘s Mac on 15/12/27.
// Copyright © 2015年 Dragon Mac. All rights reserved.
//
#import "ViewController.h"
#import "DataApi.h"
#import "QRCodeGenerator.h"
#import "TableViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)item1:(id)sender
{
TableViewController*t = [[TableViewController alloc] init];
[self.navigationController pushViewController:t animated:YES];
}
- (IBAction)btn1:(id)sender
{
UIImage* image = [QRCodeGenerator qrImageForString:_contentTF.text imageSize:_image1.frame.size.width];
_image1.image = image;
NSString* path = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, 1)lastObject]stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.png",_contentTF.text]];
NSLog(@"%@",path);
//写入文件
[UIImagePNGRepresentation(image) writeToFile:path atomically:1];
[[DataApi sharedDataApi] insertDataToSzzWithName:_contentTF.text];
}
@end
#import "TableViewController.h"
#import "DataApi.h"
@interface TableViewController ()
{
NSArray* arrData;
}
@end
@implementation TableViewController
- (void)viewDidLoad {
[super viewDidLoad];
arrData = [[DataApi sharedDataApi]getAllData];
}
-(void)viewWillAppear:(BOOL)animated
{
arrData = [[DataApi sharedDataApi]getAllData];
[self.tableView reloadData];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return arrData.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString* cellid = @"cellid";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellid];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellid];
}
NSDictionary* dic = arrData[indexPath.row];
cell.textLabel.text = dic[@"name"];
NSString* path = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, 1)lastObject]stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.png",dic[@"name"]]];
UIImage* ima = [UIImage imageWithContentsOfFile:path];
cell.imageView.image = ima;
// Configure the cell...
return cell;
}
标签:
原文地址:http://www.cnblogs.com/shitailong111/p/5080870.html