分类目录归档:iOS/Objective-C

iOS WebSocket 长链接

websocket

WebSocket是通过单个TCP连接提供全双工(双向通信)通信信道的计算机通信协议。用户可以向服务器发送消息并接收事件驱动的响应,而无需轮询服务器。 它可以让多个用户连接到同一个实时服务器,并通过API进行通信并立即获得响应。它于http通信最大的区别是双向通信,可以由服务端主动向客户端发送消息,不需要由客户端发起轮询。

在ios中实现

本文采用目前最为广泛使用的 SocketRocket , 先使用cocoapod引入该库
继续阅读

xcode9 打包报错问题解决

xcodebuild -workspace HuLaVenue.xcworkspace -scheme HLCG -configuration Debug clean -archivePath /目录/HuLaVenue-dev-315 archive CODE_SIGN_IDENTITY=”iPhone Developer: xxxxxxxx” PROVISIONING_PROFILE=”UUIDUUIDUUIDUUIDUUIDUUID”

xcodebuild -exportArchive -archivePath /目录/HuLaVenue-dev-315.xcarchive -exportPath /目录/build -exportOptionsPlist /目录/export-dev.plist

2017-09-21 15:18:04.806 xcodebuild[8273:56611] [MT] IDEDistribution: -[IDEDistributionLogging _createLoggingBundleAtPath:]: Created bundle at path ‘/var/folders/d7/cpr_njpd7_gf29sww6x6k0pc0000gn/T/HLCG_2017-09-21_15-18-04.806.xcdistributionlogs’.
2017-09-21 15:18:05.405 xcodebuild[8273:56611] [MT] IDEDistribution: Step failed: : Error Domain=IDEDistributionSigningAssetStepErrorDomain Code=0 “Locating signing assets failed.” UserInfo={NSLocalizedDescription=Locating signing assets failed., IDEDistributionSigningAssetStepUnderlyingErrors=(
“Error Domain=IDEProvisioningErrorDomain Code=9 \”\”HLCG.app\” requires a provisioning profile with the Associated Domains and Push Notifications features.\” UserInfo={NSLocalizedDescription=\”HLCG.app\” requires a provisioning profile with the Associated Domains and Push Notifications features., NSLocalizedRecoverySuggestion=Add a profile to the \”provisioningProfiles\” dictionary in your Export Options property list.}”
)}
error: exportArchive: “HLCG.app” requires a provisioning profile with the Associated Domains and Push Notifications features.

Error Domain=IDEProvisioningErrorDomain Code=9 “”HLCG.app” requires a provisioning profile with the Associated Domains and Push Notifications features.” UserInfo={NSLocalizedDescription=”HLCG.app” requires a provisioning profile with the Associated Domains and Push Notifications features., NSLocalizedRecoverySuggestion=Add a profile to the “provisioningProfiles” dictionary in your Export Options property list.}

** EXPORT FAILED **

Build step ‘Execute shell’ marked build as failure
Finished: FAILURE

 

 

解决办法:编辑plist文件 添加
解决办法:编辑plist文件 添加
provisioningProfiles
com.hula.xxxxxx
HulaVenueDev (此处名字获得见下文)

继续阅读

Objective-C Runtime

一、简介

Runtime,Objecive-c运行时,一套底层C语言的API。
我们平常写的OC底层都是基于Runtime来实现的, 例如:

//注意使用以下代码,请在xcode工程设置中找到Enable Strict Checking of objc_msgSend Calls并关闭该选项。
[self tryUpgradeApp];
//其实会转化为
objc_msgSend(self, @selector(tryUpgradeApp));

//如有参数:
[self tryUpgradeApp:arg1...];
//则转为
objc_msgSend(self, @selector(tryUpgradeApp), arg1, ...);

继续阅读

iOS 从URL启动App与openURL

目标:

1、从URL启动自己或别人的App
2、传递数据

说明:

这是一个非常常用的功能,在一些第3方SDK中也常用集成如跳转到朋友圈分享微信支付,以及调回来之后的处理等。我们看下怎么实现:

实现:

继续阅读

iOS开发 UniversalLinks支持通用链接。

介绍

UniversalLinks 是iOS9退出的一个新特性,其作用为离开传统的scheme://方式外也可以启动app,方便在h5中调用app。(原https网页中 如采用iframe方式 调起app ,但https中的iframe.src应为https地址,故而对scheme://方式的兼容性并不到位。如为http方则没有这个问题)。

作用:
1、在浏览器(safari)中H5中将加上“打开app”的按钮。
2、允许再微信等app中启动自己的app (本人实测微信中不是所有情况都可以)

实现步骤:(下列苹果开发者文章中有详细的介绍,我这边再做简单的介绍)
继续阅读

iOS 并发队列

一、GCD

GCD是apple开发中并发队列(多线程)的一个解决方案。他主要用于优化应用程序以支持多核处理器。GCD用非常简洁的方法,实现极为复杂的多线程编程。GCD是纯C的api 在ios4.0时推出。
例如

 dispatch_async(dispatch_get_global_queue(0, 0), ^{
       //在子线程执行的代码,长时间处理
        
        dispatch_async(dispatch_get_main_queue(), ^{
                //主线程刷新UI
        });
    });

上述代码中,将需要长时间运行的操作代码放入子线程,执行完毕后回到主线程继续使用。

一、GCD队列
继续阅读

iOS 第三方库 Mantle

 

Mantle 主要是简化ios中model层的第三方库,我们在项目中大量的定义和使用model,而Mantle所做的就是让我们更方便的使用model。 Mantle 目前也是我们通讯框架中最要的组成部分

直接上代码吧

HVProjectInfoModel.h

#import <Mantle/Mantle.h>
@class HVVenueWeekTimesModel;

@interface HVProjectInfoModel : MTLModel <MTLJSONSerializing>

// projectid 项目id
  //(String)
@property(nonatomic, strong) NSString* projectid;

// 项目名称
  //(String)
@property(nonatomic, strong) NSString* projectName;

//  //(List)
@property(nonatomic, strong) NSArray<HVVenueWeekTimesModel*>* scene;


+ (HVProjectInfoModel*) modelFromDictionary:(NSDictionary*)dict;

+ (NSArray<HVProjectInfoModel*>*) modelsFromArray:(NSArray<NSDictionary*>*)array;

- (NSDictionary*) dictionary;

@end

MTLJSONSerializing协议包含了一下内容

@protocol MTLJSONSerializing 
@required
+ (NSDictionary *)JSONKeyPathsByPropertyKey;
@optional
+ (NSValueTransformer *)JSONTransformerForKey:(NSString *)key;
+ (Class)classForParsingJSONDictionary:(NSDictionary *)JSONDictionary;
@end

继续阅读