iOS-02-項(xiàng)目功能大全,讓你的項(xiàng)目一天搞定(給新手們一點(diǎn)干貨)

工作了好久一直很忙随橘,好不容易有些時(shí)間喂分,今天有人問我如何開始寫一個(gè)項(xiàng)目,不禁回憶起自己寫第一個(gè)項(xiàng)目的時(shí)候机蔗,到現(xiàn)在蒲祈,突然感覺自己寫的好多都是在重復(fù),有些感想蜒车,特此寫下這篇文章讳嘱,給想入這行的新手們一些參考

1.寫項(xiàng)目之前首先我們要確定需求,明確項(xiàng)目需要實(shí)現(xiàn)哪些功能(吐槽下:好多項(xiàng)目的大部分功能都是一樣的)

2酿愧,美工沥潭,后臺(tái)啥的我都直不一一說(shuō)了情況都不一樣

廢話不說(shuō)了直接開寫程序

很重要(1)首先我們要確定明確開發(fā)需要的框架,一個(gè)好的框架可以讓我們輕松很多

框架可以自己寫嬉挡,也可以從網(wǎng)上找钝鸽,多對(duì)比一下會(huì)有驚喜的

頁(yè)面

(1)一般每個(gè)詳情頁(yè)面都有相應(yīng)的導(dǎo)航欄;如果有直接參考(見導(dǎo)航Deno汇恤,直接輸入圖片網(wǎng)址或者本地圖片,設(shè)置坐標(biāo)一鍵搞定)拔恰;如果沒有直接跳過(guò)

(2)然后就到了圖文布局了:(推薦xib或storyboard)強(qiáng)大快速(尤其項(xiàng)目比較急的時(shí)候更是不二選擇)因谎;不熟練的話那就老實(shí)的算坐標(biāo),布局吧颜懊!這個(gè)情況太多财岔,一般難度也不大,費(fèi)點(diǎn)心基本都可以搞定(我在這里就不詳細(xì)說(shuō)了河爹。)

我這里就按功能說(shuō)了(不需要就直接跳過(guò))

功能

搜索

第一種搜索:

UISearchBar?? 遵守協(xié)議

//將要進(jìn)入編輯模式調(diào)用

- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar {

//顯示cancel 按鈕

[searchBar setShowsCancelButton:YES animated:YES];

return YES;

}

//將要退出編輯模式調(diào)用

- (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar {

請(qǐng)把代碼粘貼在這里

//隱藏cancel 按鈕

[searchBar setShowsCancelButton:NO animated:YES];

return YES;

}

// 點(diǎn)擊 搜索按鈕的時(shí)候調(diào)用

- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {

//寫入搜索內(nèi)容(根據(jù)需要進(jìn)行搜索)

}

//點(diǎn)擊cancel 被調(diào)用

- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar {

//清空內(nèi)容

searchBar.text = @"";

[searchBar resignFirstResponder];//收鍵盤

}

第二種搜索

iOS8新出的感覺很強(qiáng)大匠璧,大家以后盡量都用它吧,緊跟版本呀咸这!

UISearchController :它的其中一個(gè)屬性就是searchBar

需要先設(shè)置它的搜索結(jié)果視圖

//nil為和當(dāng)前視圖總用一個(gè)視圖

self.searchVC = [[UISearchController alloc] initWithSearchResultsController:nil];

//如果不需要刻意再創(chuàng)建一個(gè)如:

UITableViewController *tableVC = [[UITableViewController alloc] initWithStyle:UITableViewStylePlain];

tableVC.tableView.delegate = self;

tableVC.tableView.dataSource = self;

[tableVC.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"];

self.searchVC = [[UISearchController alloc] initWithSearchResultsController:tableVC];

注意需要兩個(gè)協(xié)議

//搜索協(xié)議

delegate

//更新搜索內(nèi)容的代理

searchResultsUpdater

//必須要加上 自適應(yīng)才能顯示 搜索條

[self.searchVC.searchBar sizeToFit];

UISearchResultsUpdating 協(xié)議

- (void)updateSearchResultsForSearchController:(UISearchController *)searchController {

NSLog(@"searchBar 更新內(nèi)容");

//搜索內(nèi)容

//檢索推薦謂詞檢索夷恍,快準(zhǔn)狠有沒有!詳細(xì)的去百度吧度娘威武媳维!

//最后搜索數(shù)據(jù)源變了??->讓搜索控制器 內(nèi)部的結(jié)果視圖控制器的tableView的刷新

UITableViewController *tableVC = (UITableViewController *)searchController.searchResultsController;

[tableVC.tableView reloadData];

}

- (void)willPresentSearchController:(UISearchController *)searchController {

NSLog(@"searchController 將要 顯示");

}

- (void)didPresentSearchController:(UISearchController *)searchController {

NSLog(@"searchController 已經(jīng) 顯示");

}

- (void)willDismissSearchController:(UISearchController *)searchController {

NSLog(@"searchController 將要 消失");

}

- (void)didDismissSearchController:(UISearchController *)searchController {

NSLog(@"searchController 已經(jīng) 消失");

}

D鹧!如果需要頁(yè)面跳轉(zhuǎn)

在進(jìn)行頁(yè)面跳轉(zhuǎn)的時(shí)候要注意現(xiàn)在有兩個(gè)視圖呀需要區(qū)分開

UIViewController *vc = nil;

//self.presentedViewController獲取已經(jīng)模態(tài)跳轉(zhuǎn)上冊(cè)的視圖控制器侄刽,如果dismiss 之后 這個(gè)值會(huì)變成nil

if (self.presentedViewController) {

//判斷一下 當(dāng)前視圖控制器有沒有 模態(tài)跳轉(zhuǎn) 的視圖指黎,如果有 那么 做另外一個(gè)模態(tài)跳轉(zhuǎn)的時(shí)候 應(yīng)該用 上一個(gè)已經(jīng)模態(tài)跳轉(zhuǎn)的控制器進(jìn)行 模態(tài)跳轉(zhuǎn)下一個(gè)

vc = self.presentedViewController;

}else {

vc = self;

}

//模態(tài)跳轉(zhuǎn)

[vc presentViewController:alert animated:YES completion:nil];

下載

首先判斷是否已經(jīng)下載過(guò),然后告知服務(wù)器從哪里下載唠梨,

(1)下載前需要先確定路徑

獲取文件在沙盒中Documents下的全路徑

//我們把url作為文件名字-》但是url 中可能存在一些非法字符不能作為文件名袋励,這時(shí)我們可以用md5 對(duì)文件名進(jìn)行加密 產(chǎn)生一個(gè)唯一的字符串 (十六進(jìn)制的數(shù)字+A-F表示),這樣就可以保證文件名不出現(xiàn)非法字符

NSString *fileName = [url MD5Hash];//MD5

//獲取Documents

NSString *docPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)lastObject];

//拼接路徑

NSString *filePath = [docPath stringByAppendingPathComponent:fileName];

NSLog(@"path:%@",filePath);

***這里需要用到OC文件管理的知識(shí)当叭!

//創(chuàng)建文件(首先檢測(cè)有沒有存在,如果沒有在創(chuàng)建)

if (![[NSFileManager defaultManager] fileExistsAtPath:filePath]) {

//檢測(cè)文件是否存在

//不存在那么要?jiǎng)?chuàng)建

//NSFileManager 文件管理句柄

[[NSFileManager defaultManager] createFileAtPath:filePath contents:nil attributes:nil];

}

//如果已存在獲取已近下載的大小盖灸,如果不存在那么大小為0蚁鳖;

NSDictionary *fileDict = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:nil];

//保存已經(jīng)下載文件的大小

self.loadedFileSize = fileSize;

//下載前需要打開文件

self.fileHandle = [NSFileHandle fileHandleForWritingAtPath:filePath];

*****(如果服務(wù)器支持可變斷點(diǎn)續(xù)傳可以照用,如果不支持請(qǐng)忽略 頭域)

//把文件大小告知服務(wù)器

//創(chuàng)建可變請(qǐng)求 增加請(qǐng)求頭

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]];

//增加頭域 告知服務(wù)器 從 哪個(gè)字節(jié)之后開始下載(不了解頭域的還是那句話百度)赁炎,不支持頭域的可以直接跳過(guò)

[request addValue:[NSString stringWithFormat:@"bytes=%llu-",fileSize] forHTTPHeaderField:@"Range"];

//創(chuàng)建請(qǐng)求連接 開始異步下載

_httpRequest = [[NSURLConnection alloc] initWithRequest:request delegate:self];

NSURLConnectionDataDelegate

//接收服務(wù)器響應(yīng)

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {

在這里我們可以計(jì)算文件的總大小醉箕,獲取數(shù)據(jù)的類型 : httpResponse.MIMEType ,數(shù)據(jù)的大嗅愕妗: NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response

NSLog(@"url:%@",httpResponse.URL.absoluteString);

//計(jì)算文件總大小 = 已經(jīng)下載的+服務(wù)器將要發(fā)的

( self.loadedFileSize和上面關(guān)聯(lián)著??數(shù)據(jù)是一段一段下載的)

self.totalFileSize = self.loadedFileSize+httpResponse.expectedContentLength;

}

//接收數(shù)據(jù)過(guò)程 一段一段接收

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {

//都是OC文件管理的知識(shí)讥裤,我就不細(xì)說(shuō)了吧

//下載一段 寫一段數(shù)據(jù)

//先把文件偏移量定位到文件尾

[_fileHandle seekToEndOfFile];

//寫文件

[_fileHandle writeData:data];

//立即同步到磁盤

[_fileHandle synchronizeFile];

//記錄已經(jīng)下載數(shù)據(jù)大小

self.loadedFileSize += data.length

}

//下載完成一定要關(guān)閉呀

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {

[self stopDownload];//停止下載

}

//下載失敗也要關(guān)閉呀

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {

[self stopDownload];

}

- (void)stopDownload {

if (_httpRequest) {

[_httpRequest cancel];

_httpRequest = nil;

}

[_fileHandle closeFile];//關(guān)閉文件

}


收藏(關(guān)注)

這和數(shù)據(jù)庫(kù)有關(guān)聯(lián)(數(shù)據(jù)庫(kù)下面我會(huì)說(shuō)的,不懂得也可以先看后面的數(shù)據(jù)庫(kù))

點(diǎn)擊收藏按鈕的時(shí)候相當(dāng)于在數(shù)據(jù)庫(kù)里面增加了一條數(shù)據(jù)

和關(guān)注按鈕基本一樣姻报,有時(shí)候只是表現(xiàn)形似不同罷了本質(zhì)都是一樣

這里我用的是DBManager

//關(guān)于數(shù)據(jù)庫(kù)的方法己英,自己寫的,就是這里面記錄的都是收藏過(guò)得數(shù)據(jù)

//獲取所有的收藏過(guò)得數(shù)據(jù)吴旋,放在數(shù)組里

self.favoriteArr = [[DBManager sharedManager]fetchall];

然后遍歷數(shù)組獲取相關(guān)圖片的的URL下載圖片

for (int i = 0; i<_self.favoriteArr.count; i++) {

AppModel *model = _favoriteArr;

//我這里建個(gè)button 來(lái)顯示收藏(具體問題具體分析說(shuō)白了就是把你收藏的東西展現(xiàn)出來(lái))圖片下載用的是SDimage第三方庫(kù)

UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];

[btn sd_setImageWithURL:[NSURL URLWithString:model.iconUrl] forState:UIControlStateNormal placeholderImage:[UIImage imageNamed: @"account_candou"]];

损肛。

厢破。

}

登錄和注冊(cè)(每個(gè)App必備的功能)

分為 治拿,自身登錄*注冊(cè)(自己起的名字知道大概意思就行了哈摩泪,別在意哈) 和 第三方登錄(微博,QQ劫谅,微信见坑,等外國(guó)的不常用,基本就是那幾個(gè)社交的捏检,忘了還有人人(話說(shuō)沒多少人用了吧)荞驴,第三方遵循的基本原則:那個(gè)人多就用那個(gè))

主要說(shuō)下自身登錄*注冊(cè)

大多數(shù)登錄和注冊(cè)都用的是post請(qǐng)求{這里需要我們和做服務(wù)器的協(xié)調(diào)好,登陸成功未檩,登錄失敗返回什么

我們根據(jù)這些來(lái)提示用戶是否登陸成功戴尸,!

如果用戶登錄成功我們需要記錄用戶登錄成功這個(gè)狀態(tài)冤狡,以防止用戶多次登錄孙蒙,重復(fù)登錄

這時(shí)我們需要定義一個(gè)全局變量

在登錄成功后記錄登錄狀態(tài)

extern:引入外部變量

extern BOOL isLogin;

isLogin=YES;

在其他頁(yè)面再需要登錄的先判斷登錄狀態(tài),如果為YES就不需要在登陸了悲雳,如果沒有提示用戶需要登錄后才可以進(jìn)入

}

第三方登錄直接到開放平臺(tái)下demo挎峦;

清除緩存

這里我用的SDimage庫(kù)的

#import "UIImageView+WebCache.h"

-(double)getCachesSize

{

//SDimage緩存

NSInteger sdfileSize=[[SDImageCache sharedImageCache]getSize];?? NSString*caches=[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)lastObject];

NSString*mycacehs=[caches stringByAppendingPathComponent:@"MyCaches"];

NSDirectoryEnumerator*enumor=[[NSFileManager defaultManager]enumeratorAtPath:mycacehs];

NSUInteger mysize=0;

for (NSString *filename in enumor) {

NSString*filepath=[mycacehs??stringByAppendingPathComponent:filename];

NSDictionary*filedict=[[NSFileManager defaultManager]attributesOfItemAtPath:filepath error:nil];

//自身緩存

mysize+=filedict.fileSize;

}

return (mysize+sdfileSize)/1024.0/1024.0;

}

分享

:(系統(tǒng)的和第三方的: 第三方的推薦友盟(簡(jiǎn)單呀兩句話sdk:直接抄不用改省事哈哈,不過(guò)就一個(gè)微博可以用合瓢,如果想用QQ坦胶,微信,等晴楔,自有大家蛋疼的去對(duì)著文檔來(lái)吧顿苇,))

系統(tǒng)的:

協(xié)議:MFMessageComposeViewControllerDelegate(信息),MFMailComposeViewControllerDelegate(郵箱)

1(信息)

//需要真機(jī),虛擬機(jī)沒效果

if ([MFMessageComposeViewController canSendText]) {

//檢測(cè) 當(dāng)前應(yīng)用 是否支持短信功能

//支持的話 創(chuàng)建??具有短信模塊的界面

MFMessageComposeViewController *message = [[MFMessageComposeViewController alloc] init];

//設(shè)置聯(lián)系人 (可以群發(fā))

message.recipients = @[@"10086",@"10011"];

//設(shè)置短信的內(nèi)容

message.body = [NSString stringWithFormat:@"快來(lái)下載税弃,這里有驚喜:%@“,@“網(wǎng)址”];

message.messageComposeDelegate = self;

//模態(tài)跳轉(zhuǎn)(內(nèi)部有導(dǎo)航)

[self presentViewController:message animated:YES completion:nil];

}

//協(xié)議

- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result {

switch (result) {

case MessageComposeResultCancelled:

{

NSLog(@"取消");

}


break;

case MessageComposeResultSent:

{

NSLog(@"短信已發(fā)送");

}

break;

case MessageComposeResultFailed:

{

NSLog(@"短信失敗");

}

break;

default:

break;

}

//最后要模態(tài)跳轉(zhuǎn)返回

[controller dismissViewControllerAnimated:YES completion:nil];

}

(2)郵箱

if ([MFMailComposeViewController canSendMail]) {

//檢測(cè)是否支持郵箱功能

//如果支持 創(chuàng)建界面

MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init];

//設(shè)置聯(lián)系人

[mail setToRecipients:@[@"xxxxx@qq.com”,@“zzzz@163.com"]];

//設(shè)置抄送

[mail setCcRecipients:@[@"xxx@sina.com"]];

//設(shè)置標(biāo)題

[mail setSubject:@"分享愛限免應(yīng)用"];

//設(shè)置內(nèi)容

NSString *str = [NSString stringWithFormat:@"點(diǎn)擊有驚喜:%@“,@“網(wǎng)址”];

//第二個(gè)參數(shù) 是否以HTML格式

[mail setMessageBody:str isHTML:YES];

//添加附件

NSData *data = UIImagePNGRepresentation([UIImage??imageNamed: @"account_candou"]);

//第一個(gè)參數(shù) 文件二進(jìn)制??2 文件的類型 3??文件的名字

[mail addAttachmentData:data mimeType:@"image/png" fileName:@"account_candou"];

//設(shè)置代理

mail.mailComposeDelegate = self;

//模態(tài)跳轉(zhuǎn)

[self presentViewController:mail animated:YES completion:nil];

}

//協(xié)議

- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {

switch (result) {

case MFMailComposeResultCancelled:

NSLog(@"郵件取消");

break;

case MFMailComposeResultSaved:

NSLog(@"郵件保存");

break;

case MFMailComposeResultSent:

NSLog(@"郵件發(fā)送");

break;

case MFMailComposeResultFailed:

NSLog(@"郵件失敗");

break;

default:

break;

}

//模態(tài)跳轉(zhuǎn)返回

[self dismissViewControllerAnimated:YES completion:nil];

}

//友盟的(不懂可以看官網(wǎng))建立使用UM的 纪岁,系統(tǒng)的太坑了,在咱們這沒人用呀

//協(xié)議

UMSocialUIDelegate

[UMSocialSnsService presentSnsIconSheetView:self appKey:@"507fcab25270157b37000010" shareText:str??shareImage:[UIImage imageNamed: @"account_candou"] shareToSnsNames:[NSArray arrayWithObjects:UMShareToSina,UMShareToSms,UMShareToEmail,UMShareToWechatTimeline,nil] delegate:self];(寫了這么多也就前三個(gè)有用微信需要自己去注冊(cè))

在appdelgete.m中(其他的则果,哎都是淚看文檔把幔翰,你妹的呀)

//初始化UM

- (void)initUM {

//初始化

[UMSocialData setAppKey:@"507fcab25270157b37000010"];

}

地圖

又到了都是淚的地方,文檔走起吧西壮,大蘋果太渣

推薦百度遗增,高德,騰訊(百度最好款青,但是那啥注冊(cè)一把淚呀)

(1)定位:

//1.頭文件

#import

協(xié)議 CLLocationManagerDelegate

//必須要強(qiáng)引用 在定位之前不能釋放

@property (nonatomic,strong) CLLocationManager *manager;

kCLLocationAccuracyBestForNavigation?? -->最好的精度 用于導(dǎo)航

kCLLocationAccuracyBest;//精度高的

kCLLocationAccuracyNearestTenMeters;?? 10m

kCLLocationAccuracyHundredMeters;??100m

kCLLocationAccuracyKilometer;????1000m

kCLLocationAccuracyThreeKilometers;??3000m

//精度越高 越耗電

- (void)initLocationManager {

//用的時(shí)候才創(chuàng)建 懶加載

if (!self.manager) {

//實(shí)例化 管理器

self.manager = [[CLLocationManager alloc] init];

//設(shè)置精度類型

self.manager.desiredAccuracy = kCLLocationAccuracyBest;

//設(shè)置 精度的大小

self.manager.distanceFilter = 10;

//獲取定位的數(shù)據(jù) 必須要設(shè)置代理

self.manager.delegate = self;

//iOS8之后 必須要向用戶申請(qǐng)授權(quán)

/*

1.在Info.plist中 添加選項(xiàng)

Privacy - Location Usage Description(可選)

NSLocationAlwaysUsageDescription(和代碼要對(duì)應(yīng))

或者

NSLocationWhenInUseUsageDescription(代碼要對(duì)應(yīng))

2.在代碼中 添加

[self.manager requestAlwaysAuthorization];

或者

[self.manager requestWhenInUseAuthorization];

*/

double v = [UIDevice currentDevice].systemVersion.doubleValue;

if (v >= 8.0) {//判斷版本

//設(shè)置一個(gè)就可以

//始終允許授權(quán)打開定位 (前后臺(tái)都允許)

[self.manager requestAlwaysAuthorization];

//使用的時(shí)候允許 (前臺(tái)允許)

//[self.manager requestWhenInUseAuthorization];//

//允許之后 第一次 會(huì)彈出一個(gè)警告框 選擇允許

}

//下面的條件編譯也可以 判斷當(dāng)前系統(tǒng) 版本

#ifdef __IPHONE_8_0 //如果定義過(guò)這個(gè)宏__IPHONE_8_0做修,iOS8.0之后就會(huì)定義宏__IPHONE_8_0

#endif

}

}

//開始定位

- (void)startLocation:(UIBarButtonItem *)item {

//判斷是否具備定位功能

if ([CLLocationManager locationServicesEnabled]) {

//懶加載管理器

[self initLocationManager];

//開始定位

[self.manager startUpdatingLocation];

}

}


//停止定位

- (void)stopLocation:(UIBarButtonItem *)item {

[self.manager stopUpdatingLocation];

}

定位協(xié)議

//當(dāng)定位的位置 發(fā)生改變的時(shí)候 一會(huì)一直調(diào)用

//會(huì)把定位的地理位置 傳入

//locations 存放的就是地理位置

//數(shù)組中就一個(gè)元素

//

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {

if (locations.count) {

//獲取定位 位置

CLLocation *location = [locations lastObject];

//得到經(jīng)緯度

CLLocationCoordinate2D coordinate = location.coordinate;

//打印經(jīng)緯度

NSLog(@"location:%f %f",coordinate.longitude,coordinate.latitude);

//地理反編碼

//把經(jīng)緯度裝化為具體的地址

#if 0

[self reverseGeocoderWithBaidu:coordinate];

#else

[self reverseGeocoderWithSystem:location];

#endif

}

}

//百度的

//需要OCJson解析

- (void)reverseGeocoderWithBaidu:(CLLocationCoordinate2D)coordinate {

//用多線程 異步下載

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:kPathUrl,coordinate.latitude,coordinate.longitude]]];

//json解析

NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];

NSDictionary *resultDict = dict[@"result"];

NSLog(@"address:%@",resultDict[@"formatted_address"]);//獲取地址

});

}

//系統(tǒng) 地理反編碼

- (void)reverseGeocoderWithSystem:(CLLocation*)location {

//創(chuàng)建對(duì)象

CLGeocoder *geocoder = [[CLGeocoder alloc] init];

//根據(jù)location內(nèi)部的經(jīng)緯度 進(jìn)行 地理反編碼

[geocoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error) {

//placemarks??我們要的反編碼信息

for (CLPlacemark *placemark in placemarks) {

NSLog(@"country:%@",placemark.country);

NSLog(@"name:%@",placemark.name);

//遍歷地址字典

for (NSString *key in placemark.addressDictionary) {

NSLog(@"%@",placemark.addressDictionary[key]);

}

}

}];

}

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {

NSLog(@"定位失敗");

}

(2)導(dǎo)航:在定位的基礎(chǔ)的延伸

(3)查詢:在定位的基礎(chǔ)的延伸

(4)地圖:

我把系統(tǒng)的說(shuō)了,其他的百度和高德,騰訊的自己下()

和定位很類似

#import

協(xié)議

MKMapViewDelegate

@property (nonatomic, strong) MKMapView *mapView;//地圖

(void)initMapView {

[self initManager];//需要定位 就調(diào)用

//實(shí)例化 地圖

self.mapView = [[MKMapView alloc] initWithFrame:self.view.bounds];

self.mapView.mapType = MKMapTypeStandard;

//設(shè)置地圖顯示的 區(qū)域 (給一個(gè)中心位置)

// 給一個(gè) 經(jīng)緯度 和 縮放比例(0.01---0.05)

//34.77274892, 113.67591140

self.mapView.region = MKCoordinateRegionMake(CLLocationCoordinate2DMake(34.77274892, 113.67591140),MKCoordinateSpanMake(0.01, 0.01));

//是否顯示 用戶位置

self.mapView.showsUserLocation = YES;

//設(shè)置代理

self.mapView.delegate = self;//可以操作點(diǎn)標(biāo)注

//粘貼地圖

[self.view addSubview:self.mapView];

//增加大頭針(需要就創(chuàng)建不需要可以無(wú)視)

[self createAnnotation];

}

協(xié)議方法

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id)annotation {

if ([annotation isKindOfClass:[MKPointAnnotation class]]) {

//判斷是哪一類點(diǎn)標(biāo)注數(shù)據(jù)

//創(chuàng)建 點(diǎn)標(biāo)注視圖 (采用復(fù)用機(jī)制)

//隊(duì)列獲取空閑的

MKPinAnnotationView *pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"MKPinAnnotationView"];

if (pinView == nil) {

//沒有那么創(chuàng)建新的

pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"MKPinAnnotationView"];

}

//設(shè)置屬性(不需要的可以不設(shè)置)

//是否顯示氣泡

pinView.canShowCallout = YES;

//是否有掉落的動(dòng)畫

pinView.animatesDrop = YES;//(點(diǎn)標(biāo)注視圖子類MKPinAnnotationView才可以設(shè)置)

//設(shè)置大頭針視圖的顏色??紅??綠??紫三種

pinView.pinColor =??MKPinAnnotationColorPurple;

//設(shè)置氣泡的左右側(cè)附件

UIView *redView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];

redView.backgroundColor = [UIColor redColor];

pinView.leftCalloutAccessoryView = redView;

UIButton *button = [UIButton buttonWithType:UIButtonTypeInfoLight];

button.frame = CGRectMake(0, 0, 30, 30);

//氣泡附件 如果是UIControl的子類 不需要再增加事件缓待,有一個(gè)協(xié)議的方法可以替代

//[button addTarget:<#(id)#> action:<#(SEL)#> forControlEvents:<#(UIControlEvents)#>];

pinView.rightCalloutAccessoryView = button;

return pinView;//返回對(duì)象地址

}

}

如果需要的還可以添加手勢(shì)

- (void)createLongPress {

UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)];

[self.mapView addGestureRecognizer: longPress];

}

根據(jù)手勢(shì)做出不同的調(diào)用

- (void)longPress:(UILongPressGestureRecognizer *)press {

}

數(shù)據(jù)庫(kù)

sqlite(一般我們不直接向數(shù)據(jù)庫(kù)進(jìn)行操作蚓耽,使用 第3方庫(kù)來(lái)操作數(shù)據(jù)庫(kù),方便快速旋炒,但不能認(rèn)為這些庫(kù)就能存儲(chǔ)數(shù)據(jù)步悠,簡(jiǎn)單點(diǎn)理解這玩意就是中介)

常用的有FMDB(開源庫(kù))??coredata(官方系統(tǒng)庫(kù))

常用的數(shù)據(jù)庫(kù)操作,增刪改查

首先導(dǎo)入第三方庫(kù)FMDB

封裝一個(gè)類來(lái)管理數(shù)據(jù)庫(kù)

方法:

代碼操作數(shù)據(jù)庫(kù) 用fmdb 第三庫(kù)操作 sqlite

fmdb 就是 通過(guò)對(duì)C語(yǔ)言的底層函數(shù)封裝 對(duì) 數(shù)據(jù)庫(kù)進(jìn)行創(chuàng)建 增刪改查數(shù)據(jù)

步驟

1.導(dǎo)入fmdb

2.導(dǎo)入libsqlite3.dylib

3.導(dǎo)入頭文件??#import "FMDatabase.h"

4. 創(chuàng)建 數(shù)據(jù)庫(kù)

4.1打開數(shù)據(jù)庫(kù) 創(chuàng)建表

4.2 增刪改查數(shù)據(jù)??代碼執(zhí)行sql 語(yǔ)句

//導(dǎo)入頭文件

#import "FMDatabase.h"

創(chuàng)建數(shù)據(jù)庫(kù)

- (void)createDataBase {

//沙盒路徑

NSString *docPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];

//拼接 數(shù)據(jù)庫(kù)的路徑后面的數(shù)據(jù)庫(kù)的名字

NSString *dataPath = [docPath stringByAppendingPathComponent:@"myData.sqlite"];

//實(shí)例化一個(gè) fmdb 對(duì)象

NSLog(@"%@",dataPath);

_database = [[FMDatabase alloc] initWithPath:dataPath];

//如果打開成功 返回yes

//調(diào)用open 的時(shí)候 如果數(shù)據(jù)庫(kù)不存在那么就會(huì)先創(chuàng)建再打開瘫镇,如果存在直接打開

if ([_database open]) {//打開數(shù)據(jù)庫(kù)

//打開成功之后創(chuàng)建表

[self createTable];

}else{

NSLog(@"open error:%@",[_database lastErrorMessage]);//最近一次錯(cuò)誤

}

//數(shù)據(jù)庫(kù) 一般 只打開一次??這樣可以提高效率

}

創(chuàng)建表格

//其實(shí)的在數(shù)據(jù)庫(kù)里面創(chuàng)建表是一樣只不過(guò)用庫(kù)來(lái)代創(chuàng)建方便(和用中介找房子一樣的)

//user是表名(后面的表的屬性)

- (void)createTable {

NSString *sql = @"CREATE TABLE if not exists user (serial integer??Primary Key Autoincrement,num integer,name Varchar(256),mydate datetime,headimage blob)";

//執(zhí)行 sql 語(yǔ)句 成功返回yes 失敗返回no

BOOL isSuccess = [_database executeUpdate:sql];

if (!isSuccess) {

NSLog(@"create table error:%@",_database.lastErrorMessage);

}

}

//增加數(shù)據(jù)

- (void)insertData {

NSInteger num = arc4random()%69+1;

NSString *name = [NSString stringWithFormat:@"xiaohong%u",arc4random()%100];

//時(shí)間

NSDate *date = [NSDate date];

//圖片要存成二進(jìn)制

NSData *imageData = UIImagePNGRepresentation([UIImage imageNamed: @"0"]);

//要用 ? 占位符 在sql 中 ? 表示的是對(duì)象的占位符

// ???對(duì)應(yīng)的必須是一個(gè) OC的對(duì)象的地址

//增加 sql 語(yǔ)句

NSString *sql = @"insert into user(num,name,mydate,headimage) values (?,?,?,?)";

//執(zhí)行sql

BOOL isS = [_database executeUpdate:sql,@(num),name,date,imageData];

if (!isS) {

NSLog(@"insert into error :%@",_database.lastErrorMessage);

}

}

//查詢

- (void)fetchAllData{

//1.sql

NSString *sql = @"select num,name,mydate,headimage from user";

//2.執(zhí)行

//會(huì)返回一個(gè)結(jié)果集合 查找的結(jié)果都在 FMResultSet中

FMResultSet *rs = [_database executeQuery:sql];

//遍歷集合

while ([rs next]) {//表示 FMResultSet中還有沒有記錄

NSInteger num = [rs intForColumnIndex:0];//根據(jù)字段索引獲取值

NSInteger num2 = [rs intForColumn:@"num"];//根據(jù)字段名字獲取值

NSLog(@"num:%ld num2:%ld",num,num2);

NSLog(@"name:%@",[rs stringForColumn:@"name"]);

NSLog(@"date:%@",[rs dateForColumn:@"mydate"]);

NSLog(@"image_length:%ld",[rs dataForColumn:@"headimage"].length);

NSLog(@"-------------------------------");

//[rs objectForColumnName:<#(NSString *)#>];//通用

}

//第一循環(huán) 遍歷第0條記錄

//第二循環(huán)??????1

//...

//直到最后沒有了記錄 循環(huán)退出

}

//更新數(shù)據(jù)

-(void)updateData

{

NSString*sql=@"update user name=? where num<50 ";

if ([_database executeUpdate:sql,@"小紅" ]) {

NSLog(@"updata error:%@",_database.lastErrorMessage);

}

}}

}

//刪除數(shù)據(jù)

-(void)deletedatawithNUm:(NSInteger)num

{

NSString*sql=@"delete from user where num=?";

if ([_database executeUpdate:sql,@(num)]) {

NSLog(@"%@",_database.lastErrorMessage);

}

}

coredata蘋果官方的效果棒棒噠鼎兽,也很好用

首先先右鍵—》newfile—> (iOS )core data—>DataModel??完成后會(huì)有類名.xcdatamodel文件,可視化操作铣除,創(chuàng)建表(注意改下表名字谚咬,默認(rèn)的有可能關(guān)聯(lián)不上)徙瓶,然后在表里面添加屬性川蒙,完成后右鍵—》newfile—> (iOS )core data—>NSManagerObject subclass ,然后和你的表關(guān)聯(lián)一下model層就創(chuàng)建出來(lái)了,

下面就是封裝一個(gè)類來(lái)專門管理coredata,方便我們對(duì)數(shù)據(jù)庫(kù)盡心操作

導(dǎo)入頭文件

#import

/設(shè)計(jì)一個(gè)單例類 管理數(shù)據(jù)庫(kù)

@interface CoreDataManager : NSObject

//非標(biāo)準(zhǔn)單例

+ (instancetype)defaultManager;

//上下文管理對(duì)象

@property (nonatomic,strong) NSManagedObjectContext *context;

//增刪改查

//增加一個(gè)數(shù)據(jù)

- (void)insertDataWithName:(NSString *)name age:(int)age;

//根據(jù)名字刪除

- (void)deleteDataWithName:(NSString *)name;

//修改數(shù)據(jù) 根據(jù)名字修改年齡

- (void)updateDataWithName:(NSString *)name age:(int)age;

//查詢

//查詢所有的數(shù)據(jù)

- (NSArray *)fetchAllData;

//根據(jù)名字查找

- (NSArray *)fetchDataWithName:(NSString *)name;

實(shí)現(xiàn)方法:

//(創(chuàng)建單例類的方法網(wǎng)上有好多)

+ (instancetype)defaultManager {

static CoreDataManager *manager = nil;

@synchronized(self) {

manager = [[self alloc] init];

}

return manager;

}

//初始化準(zhǔn)備工作

//1.導(dǎo)入頭文件 CoreData/CoreData.h

//2.創(chuàng)建一個(gè) 一個(gè)數(shù)據(jù)模型文件(和數(shù)據(jù)庫(kù)中的表類似)醉鳖,里面創(chuàng)建一些數(shù)據(jù)模型(設(shè)計(jì)屬性)

//3.設(shè)計(jì) 一個(gè)數(shù)據(jù)模型類(根據(jù)數(shù)據(jù)模型文件)

//術(shù)語(yǔ)不明白的度娘走起(我就不嘮叨了)

- (instancetype)init {

if (self = [super init]) {

//1.將數(shù)據(jù)模型文件中的 的模型 放入 modelFile 指向的 對(duì)象中

//關(guān)聯(lián)數(shù)據(jù)模型

NSManagedObjectModel *modelFile = [NSManagedObjectModel mergedModelFromBundles:nil];

//2.設(shè)置 存儲(chǔ) 協(xié)調(diào)器??(協(xié)調(diào) 底層和上層)

//2.1讓 協(xié)調(diào)器 和 modelFile產(chǎn)生關(guān)聯(lián)

NSPersistentStoreCoordinator *coordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:modelFile];

//2.2設(shè)置數(shù)據(jù)庫(kù)文件的路徑

NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"/Documents/Mydata.sqlite"];

NSError *error = nil;

//2.3設(shè)置 存儲(chǔ)方式 根據(jù)路徑創(chuàng)建 數(shù)據(jù)庫(kù)文件

///將coreData數(shù)據(jù)??映射到數(shù)據(jù)庫(kù)

NSPersistentStore *store = [coordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:[NSURL fileURLWithPath:path] options:nil error:&error];

if (!store) {

//創(chuàng)建 失敗

NSLog(@"creat store falied:%@",error.localizedDescription);

return nil;

}

//3.托管對(duì)象 /上下文管理對(duì)象

self.context = [[NSManagedObjectContext alloc] init];

//托管對(duì)象 和 協(xié)調(diào)器 產(chǎn)生 關(guān)聯(lián)

self.context.persistentStoreCoordinator = coordinator;

//_context 對(duì)數(shù)據(jù)庫(kù) 進(jìn)行增刪改查

}

return self;

}

下面就是增刪改查了

//增加一個(gè)數(shù)據(jù)

- (void)insertDataWithName:(NSString *)name age:(int)age {

//1.給_context 操作的數(shù)據(jù) 增加一個(gè)UserModel實(shí)例對(duì)象

//用 NSEntityDescription來(lái)增加

UserModel *model = (UserModel *)[NSEntityDescription insertNewObjectForEntityForName:@"UserModel" inManagedObjectContext:self.context];

model.name = name;

model.age = @(age);

model.fName = [name substringToIndex:1];

//保存數(shù)據(jù)

[self saveDataWithType:@"addData"];

}

- (void)saveDataWithType:(NSString *)type {

NSError *error = nil;

//回寫 保存到數(shù)據(jù)庫(kù)文件

if (![self.context save:&error]) {

//保存失敗

NSLog(@"%@:%@",type,error.localizedDescription);

}

}

//根據(jù)名字刪除

- (void)deleteDataWithName:(NSString *)name {

//根據(jù)名字 找到對(duì)象

NSArray *arr = [self fetchDataWithName:name];

//遍歷數(shù)組

for (UserModel *model in arr) {

[self.context deleteObject:model];

}

//保存數(shù)據(jù)

[self saveDataWithType:@"deleteData"];

}

//修改數(shù)據(jù) 根據(jù)名字修改年齡

- (void)updateDataWithName:(NSString *)name age:(int)age{

//1.根據(jù)名字 找到對(duì)象

NSArray *arr = [self fetchDataWithName:name];

//2.遍歷數(shù)組

for (UserModel *model in arr) {

model.age = @(age);

}

//3.保存數(shù)據(jù)

[self saveDataWithType:@"updateData"];

}

//查詢

//查詢所有的數(shù)據(jù)

- (NSArray *)fetchAllData {

return [self fetchDataWithName:nil];

}

根據(jù)名字 在數(shù)據(jù)庫(kù)中 查找 數(shù)據(jù)模型對(duì)象

//根據(jù)名字查找

- (NSArray *)fetchDataWithName:(NSString *)name {

//1.先設(shè)置查找請(qǐng)求

NSFetchRequest *request = [[NSFetchRequest alloc] init];

//2.設(shè)置 查找的數(shù)據(jù)模型對(duì)象

request.entity = [NSEntityDescription??entityForName:@"UserModel" inManagedObjectContext:_context];

//3.設(shè)置 謂詞 (根據(jù)條件 找要設(shè)置謂詞)

if (name) {

//name 不是nil 那么就根據(jù)名字找 設(shè)置謂詞

//要查詢 一個(gè)對(duì)象的 匹配的屬性 那么需要設(shè)置謂詞

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name like %@",name];

request.predicate = predicate;

}

//還可以設(shè)置排序 從小到大 或者從大到小

//按照年齡降序 的一個(gè)描述

NSSortDescriptor *sort1 = [NSSortDescriptor sortDescriptorWithKey:@"age" ascending:NO];

//按照 name 進(jìn)行 升序排列

NSSortDescriptor *sort2 = [NSSortDescriptor sortDescriptorWithKey:@"name" ascending:YES];

#if 0

request.sortDescriptors = @[sort1];//按照一個(gè)準(zhǔn)則排序 age

#else

//先按照 age 進(jìn)行降序排 郎嫁,如果出現(xiàn)age 相同 那么 再按照name 升序排序

request.sortDescriptors = @[sort1,sort2];

#endif

//不設(shè)置 謂詞 那么找所有

//5.執(zhí)行 查詢請(qǐng)求??返回一個(gè)數(shù)組

NSArray *resultArr = [_context executeFetchRequest:request error:nil];

return resultArr;

}

封裝以后直接調(diào)就行了

二維碼(多關(guān)注點(diǎn)github好東西很多的)

第三方庫(kù)ZBarSDK

導(dǎo)入庫(kù)

導(dǎo)入系統(tǒng)庫(kù)

libz.dylib

libicony.dylib

QuartzCore.framework

CoreVideo.framework

CoreMedia.framework

AVfoundation.framwork

原理示例:

二維碼編譯順序

Zbar編譯

需要添加AVFoundation??CoreMedia??CoreVideo QuartzCore libiconv

ZCZBarViewController*vc=[[ZCZBarViewController alloc]initWithBlock:^(NSString *str, BOOL isScceed) {

if (isScceed) {

NSLog(@"掃描后的結(jié)果~%@",str);

}

}];

[self presentViewController:vc animated:YES completion:nil];

生成二維碼

拖拽libqrencode包進(jìn)入工程秉继,注意點(diǎn)copy

添加頭文件#import "QRCodeGenerator.h"

imageView.image=[QRCodeGenerator qrImageForString:@"這個(gè)是什么" imageSize:imageView.bounds.size.width];

#import "ZCZBarViewController.h"

#import "QRCodeGenerator.h"

UIButton*button=[UIButton buttonWithType:UIButtonTypeSystem];

button.frame=CGRectMake(0, 70, 100, 100);

[button addTarget:self action:@selector(btn:) forControlEvents:UIControlEventTouchUpInside];

[button setTitle:@"掃描二維碼" forState:UIControlStateNormal];

[self.view addSubview:button];

UIImageView*imageview=[[UIImageView alloc]initWithFrame:CGRectMake(100, 200, 200, 200)];

imageview.image=[QRCodeGenerator qrImageForString:@"生成二維碼" imageSize:300];

[self.view addSubview:imageview];

-(void)btn:(UIButton*)button

{

ZCZBarViewController*vc=[[ZCZBarViewController alloc]initWithBlock:^(NSString *str, BOOL isScceed) {

if (isScceed) {

NSLog(@"掃描后的結(jié)果~%@",str);

}

}];

[self presentViewController:vc animated:YES completion:nil];

}

推送

本地推送,網(wǎng)絡(luò)推送泽铛,激光推送(要錢呀尚辑!屌絲傷不起)

網(wǎng)絡(luò)推送:

應(yīng)用場(chǎng)景

提醒業(yè)務(wù),比如一些秀場(chǎng)盔腔,女主播可以通知他們的土豪(比如我)杠茬,趕緊來(lái)撒錢

每天晚上8點(diǎn)影視劇的推送

小說(shuō)更新

游戲活動(dòng)推送等

//在這個(gè)方法里面寫

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

if ([[[UIDevice currentDevice]systemVersion]floatValue]>=8.0) {

[[UIApplication sharedApplication]registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeAlert|UIUserNotificationTypeSound|UIUserNotificationTypeBadge) categories:nil]];

//開啟通知

[[UIApplication sharedApplication]registerForRemoteNotifications];

}

}

//當(dāng)我們接到通知之后,如何去處理弛随,首先去處理一個(gè)標(biāo)識(shí)

-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken

{

//我們首先獲取一個(gè)token值瓢喉,相當(dāng)于我們用的QQ,需要一個(gè)QQ號(hào)碼舀透,那么這個(gè)QQ是誰(shuí)灯荧,是蘋果服務(wù)器,我們自己通過(guò)自己的設(shè)備向蘋果服務(wù)器發(fā)送一個(gè)請(qǐng)求盐杂,告訴他們我們應(yīng)用的一個(gè)標(biāo)示,作為他們的聯(lián)系

//獲取token需要進(jìn)行處理哆窿,把這個(gè)標(biāo)示發(fā)給我們服務(wù)器端做記錄链烈,當(dāng)我們的服務(wù)器需要給用戶發(fā)消息的時(shí)候,使用這個(gè)標(biāo)示符+我們要發(fā)送的消息給蘋果服務(wù)器挚躯,拼過(guò)會(huì)根據(jù)這個(gè)標(biāo)示符發(fā)到對(duì)應(yīng)的手機(jī)的里面

//因?yàn)樵谟芯W(wǎng)的情況下强衡,手機(jī)是一直和蘋果服務(wù)器保持者聯(lián)系,從理論上來(lái)說(shuō)蘋果可以控制任何一臺(tái)手機(jī)的情況下進(jìn)行相關(guān)的操作

//最明顯的就是码荔,在有網(wǎng)的情況下漩勤,你收不到任何消息感挥,但是在有網(wǎng)的情況下會(huì)彈出很多消息

NSLog(@"%@",deviceToken );

}

//出錯(cuò)處理

-(void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error

{

NSLog(@"%@",error);

}

-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo

{

//接受推到消息的是一個(gè)字典,是規(guī)定的格式

}

本地推送:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

if ([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)]) {

[application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]];

}

/創(chuàng)建一個(gè)本地推送

UILocalNotification*local=[[UILocalNotification alloc]init];

//設(shè)置推送內(nèi)容

local.alertBody=@“親越败,什么時(shí)候約;

//設(shè)置聲音

local.soundName=@"au_gameover.wav";

//設(shè)置推送數(shù)目

local.applicationIconBadgeNumber=1000;

local.fireDate=[NSDate??dateWithTimeIntervalSinceNow:10];

//把推送任務(wù)增加到推送隊(duì)列中触幼,需要注意,推送通知后究飞,程序就算被殺掉置谦,推送通知任然可以運(yùn)行

//虛擬機(jī)上如果要看效果的話

//如果要彈出推送通知,需要程序退出后臺(tái)亿傅,快捷鍵Connand+Shitf+h

[[UIApplication sharedApplication]scheduleLocalNotification:local];

/*

//刪除通知

NSArray*localArray=[UIApplication sharedApplication].scheduledLocalNotifications;

//遍歷通知

for (UILocalNotification* notification in localArray) {

if ([notification.alertBody isEqual:@"親媒峡,什么時(shí)候約"]) {

[[UIApplication sharedApplication]cancelLocalNotification:notification];

}

}

//刪除所有的通知

// [[UIApplication sharedApplication]cancelAllLocalNotifications];

/*

本地推送的加入方式,比如判斷葵擎。3天沒來(lái)谅阿,每次程序啟動(dòng),把原來(lái)的舊通知酬滤,并且計(jì)算出3天后的時(shí)間

*/

//????NSInteger num=[UIApplication sharedApplication].applicationIconBadgeNumber;

//????num=num+1;

//????local.applicationIconBadgeNumber=num;

*/

}

//激光有Demo

VLC(網(wǎng)上有教程)

VLC集成指南

添加libMobileVLCKit

添加庫(kù)

libstdc++

libiconv

libbz2

Security

QuartzCore

CoreText

CFnetWork

OpenGLES

AudioToolbox

修改C++編譯器為stdC++

聊天(tcp-udp)

(socket庫(kù))

#import "AsyncSocket.h"

協(xié)議

AsyncSocketDelegate

//建立發(fā)送端

AsyncSocket * sendSocket;

//建立服務(wù)端

AsyncSocket * severSocket;

//建立一個(gè)數(shù)組保存連接

@property(nonatomic,strong)NSMutableArray * socketArray;

/*

建立一個(gè)群聊签餐,學(xué)生向教師端發(fā)送消息,教師端顯示所有消息

*/

- (void)CreatSocket

{

sendSocket=[[AsyncSocket alloc] initWithDelegate:self];

severSocket=[[AsyncSocket alloc] initWithDelegate:self];

//服務(wù)端綁定端口敏晤,監(jiān)聽該端口接收的數(shù)據(jù)

/*

端口最大為65535贱田,其中建議設(shè)置為5000以上,另外還有一些特殊的端口嘴脾,例如8080為視頻端口男摧,建議不要占用

*/

[severSocket acceptOnPort:5678 error:nil];

}

- (void)onSocket:(AsyncSocket *)sock didAcceptNewSocket:(AsyncSocket *)newSocket

{

//接收的一個(gè)新連接,這個(gè)連接需要保存一下译打,然后持續(xù)保持連接

[self.socketArray addObject:newSocket];

//其中-1標(biāo)示持續(xù)觀察耗拓,如果設(shè)置為300,那么300秒以后就不在觀察

[newSocket readDataWithTimeout:-1 tag:100];

}

//協(xié)議方法

- (void)onSocket:(AsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tag

{

//接收到的數(shù)據(jù)

NSString * message=[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];

if (_textView) {

//在原來(lái)的舊數(shù)據(jù)上面奏司,追加新的數(shù)據(jù)

_textView.text=[NSString stringWithFormat:@"%@%@",_textView.text,message];

}

[sock readDataWithTimeout:-1 tag:100];

}

- (void)onSocket:(AsyncSocket *)sock didWriteDataWithTag:(long)tag

{

//發(fā)送成功

}

//textfild協(xié)議

//發(fā)送數(shù)據(jù)

-(BOOL)textFieldShouldReturn:(UITextField *)textField{

if (textField.text.length>0) {

// 發(fā)送數(shù)據(jù)

if (![sendSocket isConnected]) {

//確定是否連接乔询,如果沒有連接,則開始連接host:后面是iP地址

[sendSocket connectToHost:@"192.168.2.7" onPort:5678 error:nil];

}

//當(dāng)連接完成以后韵洋,發(fā)送數(shù)據(jù)

//拼接數(shù)據(jù)是誰(shuí)說(shuō)竿刁,我希望獲得當(dāng)前設(shè)備的名稱

// [[UIDevice currentDevice]systemName];該方法只有在真機(jī)上才有效,在模擬器上無(wú)效

NSString * message=[NSString stringWithFormat:@"%@說(shuō):%@\n",@"房騫",textField.text];

[sendSocket writeData:[message dataUsingEncoding:NSUTF8StringEncoding] withTimeout:-1 tag:100];

}

return YES;

}

屏幕截圖

ZCScreenShot庫(kù)

此類用于屏幕截圖

添加庫(kù):無(wú)

代碼示例 為截取全屏

[BeginImageContext beginImageContext:self.view.frame View:self.view];

2個(gè)參數(shù) 第一個(gè)參數(shù)用于截取的范圍搪缨,第二個(gè)參數(shù)截取哪個(gè)view上

//示例代碼

[ZCScreenShot beginImageContext:self.view.frame View:self.view];

//第一個(gè)參數(shù)是截取圖片的范圍食拜,第二個(gè)參數(shù)是截取的那一層

#import "ZCScreenShot.h"

UIImage *image=[ZCScreenShot beginImageContext:self.view.frame View:self.view];

(上面兩個(gè)加起來(lái)就是一個(gè)小型教學(xué)客戶端呀)

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市副编,隨后出現(xiàn)的幾起案子负甸,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 218,682評(píng)論 6 507
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件呻待,死亡現(xiàn)場(chǎng)離奇詭異打月,居然都是意外死亡,警方通過(guò)查閱死者的電腦和手機(jī)蚕捉,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,277評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門奏篙,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái),“玉大人鱼冀,你說(shuō)我怎么就攤上這事报破。” “怎么了千绪?”我有些...
    開封第一講書人閱讀 165,083評(píng)論 0 355
  • 文/不壞的土叔 我叫張陵充易,是天一觀的道長(zhǎng)。 經(jīng)常有香客問我荸型,道長(zhǎng)盹靴,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,763評(píng)論 1 295
  • 正文 為了忘掉前任瑞妇,我火速辦了婚禮稿静,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘辕狰。我一直安慰自己改备,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,785評(píng)論 6 392
  • 文/花漫 我一把揭開白布蔓倍。 她就那樣靜靜地躺著悬钳,像睡著了一般。 火紅的嫁衣襯著肌膚如雪偶翅。 梳的紋絲不亂的頭發(fā)上默勾,一...
    開封第一講書人閱讀 51,624評(píng)論 1 305
  • 那天,我揣著相機(jī)與錄音聚谁,去河邊找鬼母剥。 笑死,一個(gè)胖子當(dāng)著我的面吹牛形导,可吹牛的內(nèi)容都是我干的环疼。 我是一名探鬼主播,決...
    沈念sama閱讀 40,358評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼朵耕,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼秦爆!你這毒婦竟也來(lái)了?” 一聲冷哼從身側(cè)響起憔披,我...
    開封第一講書人閱讀 39,261評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后芬膝,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體望门,經(jīng)...
    沈念sama閱讀 45,722評(píng)論 1 315
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,900評(píng)論 3 336
  • 正文 我和宋清朗相戀三年锰霜,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了筹误。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 40,030評(píng)論 1 350
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡癣缅,死狀恐怖厨剪,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情友存,我是刑警寧澤祷膳,帶...
    沈念sama閱讀 35,737評(píng)論 5 346
  • 正文 年R本政府宣布,位于F島的核電站屡立,受9級(jí)特大地震影響直晨,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜膨俐,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,360評(píng)論 3 330
  • 文/蒙蒙 一勇皇、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧焚刺,春花似錦敛摘、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,941評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)。三九已至匾委,卻和暖如春拖叙,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背赂乐。 一陣腳步聲響...
    開封第一講書人閱讀 33,057評(píng)論 1 270
  • 我被黑心中介騙來(lái)泰國(guó)打工薯鳍, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人挨措。 一個(gè)月前我還...
    沈念sama閱讀 48,237評(píng)論 3 371
  • 正文 我出身青樓挖滤,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親浅役。 傳聞我的和親對(duì)象是個(gè)殘疾皇子斩松,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,976評(píng)論 2 355

推薦閱讀更多精彩內(nèi)容