Wednesday, November 8, 2017

Exporting .ipa from .xcodearchive in XCode 9

Lest find out how to get .ipa file from XCode archive.

1) Prepare exportOptions.plist.


Example:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>compileBitcode</key>
<true/>
<key>method</key>
<string>ad-hoc</string>
<key>provisioningProfiles</key>
<dict>
<key>APP_BUNDLE_NAME</key>
<string>PROVISIONING_PROFILE_NAME</string>
</dict>
<key>signingCertificate</key>
<string>iPhone Distribution</string>
<key>signingStyle</key>
<string>manual</string>
<key>teamID</key>
<string>YOUR_TEAM_ID</string>
<key>thinning</key>
<string>&lt;none&gt;</string>
</dict>
</plist>
PROVISIONING_PROFILE_NAME - just name, without extension.

2) Execute command:

xcodebuild -exportArchive -archivePath app.xcarchive -exportPath /AppIPA -exportOptionsPlist exportOptions.plist

 Thats it!

Wednesday, June 1, 2016

Image caching in AFNetworking 3.0 and migration from SDWebImage

First of all I want to say few words about SDWebImage. It's great library for asynchronous image downloading with caching support. Until now I use this lib for image caching in my projects, also in this projects i use AFNetworking to send requests. And everything was great but once I find out that AFNetworking can also cache images as SDWebImage, and even SDWebImage wiki also says that if you use AFNetworking don't use SDWebImage. So i as user of the latest AFNetworking version 3.0 removed SDWebImage and start installing cache with AFNetworking.

As AFNetworking can work with UIButton and UIImageView
AFNetworking has in memory caching and on disk caching. But be careful with on disk caching, many manuals say that setup request policy will be enough:

#import <AFNetworking/UIImageView+AFNetworking.h>
#import <AFNetworking/UIButton+AFNetworking.h>
#import <AFNetworking/AFImageDownloader.h>

NSURLRequest *imageRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:url] cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:60];

But that's not true! As AFNetworking developers said: "Images are cached to disk using standard NSURLCache built in to iOS, meaning that if your responses include proper cache headers, those items should end up on disk in the cache." So to cache image on disk you response should include cache headers! How cache header may look:

"Accept-Ranges" = bytes;
"Cache-Control" = "max-age=604800";
Connection = close;
"Content-Length" = 3808;
"Content-Type" = "image/png";
Date = "Tue, 29 Mar 2016 19:55:52 GMT";
Etag = "\"5630989d-ee0\"";
Expires = "Tue, 05 Apr 2016 19:55:52 GMT";
"Last-Modified" = "Wed, 28 Oct 2015 09:42:53 GMT";
Server = nginx;

If you have such headers AFNetworking will cache you image on disk.
If you wand to get image from disk do:

NSURLRequest *imageRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:url] cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:60];
UIImage *image = [UIImage imageWithData:[[AFImageDownloader defaultURLCache] cachedResponseForRequest:imageRequest].data];

Thursday, April 14, 2016

UIViewAutoresizingMask basics



As for me autoresizing is technology from the past, new AutoLayout fully replaced it, but sometimes using Autoresizing easier that AutoLayout. In this small article you can read about setting UIViewAutoresizing programmatically.

Saturday, November 21, 2015