我正在开发一款iPhone应用程序.在开发期间,我需要连接到使用自签名SSL证书的服务器.我很确定- (void)URLSession:(NSURLSession *)session didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential *))completionHandler
我有机会编写一些异常代码来实现这一点.但是,我找不到任何资源告诉我如何做到这一点.我可以在日志中看到以下错误:
NSURLConnection/CFURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9813)
Run Code Online (Sandbox Code Playgroud)
除此之外,当我NSLog(@"error = %@", error);
从上面的委托方法中得到:
错误域= NSURLErrorDomain代码= -1202"此服务器的证书无效.您可能正在连接到假装为"api.mydevelopmenturl.com"的服务器,这可能会使您的机密信息面临风险." UserInfo = 0x10cbdbcf0 {NSUnderlyingError = 0x112ec9730"此服务器的证书无效.您可能正在连接到假装为"api.mydevelopmenturl.com"的服务器,这可能会使您的机密信息面临风险.",NSErrorFailingURLStringKey = https: //api.mydevelopmenturl.com/posts,NSErrorFailingURLKey = https://api.mydevelopmenturl.com/posts,NSLocalizedRecoverySuggestion =您是否还要连接到服务器?,NSURLErrorFailingURLPeerTrustErrorKey =,NSLocalizedDescription =此服务器的证书无效.您可能正在连接到假装为"api.mydevelopmenturl.com"的服务器,这可能会使您的机密信息面临风险.}
有关如何解决此问题的任何想法?请在我阅读概念文档时发布代码,但我不理解它们.这是一个超越我的例子:https://developer.apple.com/library/content/technotes/tn2232/_index.html
我有一个扩展NSObject
和实现MKOverlay
协议的自定义类.因此,我需要实现协议的boundingMapRect
属性,这是一个MKMapRect
.创造一个MKMapRect
我当然可以MKMapRectMake
用来做一个.但是,我不知道如何MKMapRect
使用我拥有的数据来创建两个点,每个点由纬度和经度指定.MKMapRectMake
的文档说:
MKMapRect MKMapRectMake(
double x,
double y,
double width,
double height
);
Parameters
x
The point along the east-west axis of the map projection to use for the origin.
y
The point along the north-south axis of the map projection to use for the origin.
width
The width of the rectangle (measured using map points).
height
The height of the rectangle (measured using map …
Run Code Online (Sandbox Code Playgroud) 我有一个测试应用程序设置,即使用户在下载过程中切换应用程序,它也能成功从网络下载内容.太好了,现在我有后台下载了.现在我想添加缓存.没有必要让我多次下载图像,b/c系统设计,给定一个图像URL我可以告诉你该URL后面的内容永远不会改变.所以,现在我想使用Apple内置的内存/磁盘缓存来缓存下载的结果,我已经阅读了很多(而不是我在NSCachesDirectory中手动保存文件,然后在创建之前检查文件)请求,ick).在尝试得到缓存在此工作的代码顶部的工作,我添加以下代码:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
// Set app-wide shared cache (first number is megabyte value)
[NSURLCache setSharedURLCache:[[NSURLCache alloc] initWithMemoryCapacity:60 * 1024 * 1024
diskCapacity:200 * 1024 * 1024
diskPath:nil]];
return YES;
}
Run Code Online (Sandbox Code Playgroud)
当我创建会话时,我添加了两行NEW(URLCache和requestCachePolicy).
// Helper method to get a single session object
- (NSURLSession *)backgroundSession
{
static NSURLSession *session = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration backgroundSessionConfiguration:@"com.example.apple-samplecode.SimpleBackgroundTransfer.BackgroundSession"];
configuration.URLCache = [NSURLCache sharedURLCache]; // NEW LINE …
Run Code Online (Sandbox Code Playgroud) iphone nsurlcache ios nsurlsession nsurlsessionconfiguration
我们被告知,通过Apple的文档startMonitoringSignificantLocationChanges
,使用意义更改API的应用程序可以预期以下行为:
如果您启动此服务并且您的应用程序随后终止,则系统会在新事件到达时自动将应用程序重新启动到后台.在这种情况下,传递给locationManager的选项字典:didUpdateLocations:应用程序委托的方法包含密钥UIApplicationLaunchOptionsLocationKey,以指示您的应用程序是由于位置事件而启动的.重新启动后,您仍必须配置位置管理器对象并调用此方法以继续接收位置事件.重新启动位置服务时,会立即将当前事件传递给您的代理.此外,即使在启动位置服务之前,也会使用最新的位置对象填充位置管理器对象的位置属性.
来源:Apple Docs
我的问题是,我将如何进行调试和/或测试?一旦我终止应用程序,我不知道发生了什么(即调试会话被app杀死).我什么时候才能知道iOS何时或是否已在后台启动我的应用程序w/launchOption键UIApplicationLaunchOptionsLocationKey
?更重要的是,我如何知道执行的代码块是否正常运行?我如何快速测试这种情况,而不必在终止我的应用程序后开车,希望我编写的代码神奇地起作用?任何帮助非常感谢!!
在PHP中,它是一行代码:
$array_without_empty_strs = array_filter($array_with_empty_strs);
Run Code Online (Sandbox Code Playgroud)
什么是目标C等价物?
更新 - 添加以下测试代码以说明Nikolai Ruhe解决方案的使用:
// SOLUTION Test Code
NSMutableArray *myArray = [[NSMutableArray alloc] init ];
[myArray addObject:[NSNumber numberWithInt:5]];
[myArray addObject:@""];
[myArray addObject:@"test"];
NSLog(@"%@", myArray);
[myArray removeObject:@""];
NSLog(@"%@", myArray);
// SOLUTION Test Code Output
2012-07-12 08:18:16.271 Calculator[1527:f803] (
5,
"",
test
)
2012-07-12 08:18:16.273 Calculator[1527:f803] (
5,
test
)
Run Code Online (Sandbox Code Playgroud) PHP是否具有在给定内容类型的情况下返回文件扩展名的函数?
我正在寻找像以下一样的东西:
<?php
function getFileExtension($contentType)
{
if ($contentType === 'image/png')
{
return '.png';
}
elseif ($contentType === 'image/jpg')
{
return '.jpg';
}
elseif ($contentType === 'application/zip')
{
return '.zip';
}
else
{
return FALSE;
}
}
Run Code Online (Sandbox Code Playgroud)
目标是使用处理所有内容类型的库函数.根据上面的模式,我想我可以用这样的东西自己动手:
<?php
function getFileExtension($contentType)
{
$pieces = explode('/', $contentType);
return '.' . array_pop($pieces);
}
Run Code Online (Sandbox Code Playgroud)
......但这看起来很笨拙.有人知道已经创作的PHP解决方案吗?LMK.谢谢!
如果用户在应用程序终止之前进入成功监控的区域,iOS区域监控是否会在后台启动我的应用程序?
我知道重要的更改API会这样做,并会在发布时通过包含UIApplicationLaunchOptionsLocationKey
密钥让我知道.如果区域监控也将我的应用程序从终止状态唤醒,那么启动过程是什么样的?我应该找一个特殊的钥匙吗?
从网站下载所有图像的最快最简单的方法是什么?更具体地说,http://www.cycustom.com/large/.
我正在思考wget或curl的思路.
为了澄清,首先(并且最重要的)我目前不知道如何完成这项任务.其次,我很想知道wget或curl是否有一个更容易理解的解决方案.谢谢.
---更新@sarnold ---
谢谢你的回复.我认为这也可以解决问题.但事实并非如此.这是命令的输出:
wget --mirror --no-parent http://www.cycustom.com/large/
--2012-01-10 18:19:36-- http://www.cycustom.com/large/
Resolving www.cycustom.com... 64.244.61.237
Connecting to www.cycustom.com|64.244.61.237|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: `www.cycustom.com/large/index.html'
[ <=> ] 188,795 504K/s in 0.4s
Last-modified header missing -- time-stamps turned off.
2012-01-10 18:19:37 (504 KB/s) - `www.cycustom.com/large/index.html' saved [188795]
Loading robots.txt; please ignore errors.
--2012-01-10 18:19:37-- http://www.cycustom.com/robots.txt
Connecting to www.cycustom.com|64.244.61.237|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 174 [text/plain]
Saving …
Run Code Online (Sandbox Code Playgroud) 环境:
使用Xcode版本7.1.1(7B1005)将应用程序构建到我的iPhone 6物理设备后,然后打开Apple的"Watch"应用程序,找到我的应用程序,添加然后翻转"在Apple Watch上显示应用程序".它似乎安装成功,但是当它达到100%时,刚刚完成安装的手表上的应用程序图标消失,我iPhone上的Watch应用程序中的切换开关翻转为关闭.
怎么了?我怎样才能解决这个问题?
更新,固定:
步骤1)在Xcode中转到Window> Devices.选择手表与之配对的iOS设备,查看手表设备上正在写入的日志.
步骤2)希望手表设备日志显示与安装相关的错误,然后您可以使用谷歌.在我的情况下,我发现错误"ApplicationVerificationFailed".谷歌搜索我发现:在真正的Apple Watch上调试:应用程序验证失败这让我知道配置文件相关问题.不知何故,我的手表与加载到Xcode中的配置文件无关.因此,我通过Safari将我的手表设备添加到开发中心的配置文件中,将该配置文件下载到我的comp并双击安装.这修复了我的Apple Watch安装错误.
更新:通过下面的"屏幕截图"方法大纲修复.这有效但有更优雅的方式吗?
我如何解除一堆带有动画的模态视图控制器而不在屏幕上闪烁顶部和底部之间的任何呈现的VC?尝试使用动画执行此操作无效.请参阅下面的代码和描述我的问题的内联注释.您可以将此代码复制/粘贴到Xcode中的新项目中,以便亲自查看您是否愿意!
//
// ViewController.m
// MultipleModals
//
#import "ViewController.h"
#import "MyViewController.h"
#import "MyHelper.h"
@interface ViewController ()
@end
@implementation ViewController
static BOOL doAgain = YES; // So when red appears again, we don't endlessly cycle (for testing)
- (void)viewDidAppear:(BOOL)animated
{
// Invoke super
[super viewDidAppear:animated];
// Prevent loop when we dismiss all the way back to red (for testing)
if (doAgain)
{
// Okay here's where the demo code starts...
// PRESENTING a full stack of modals WITHOUT animation WORKS …
Run Code Online (Sandbox Code Playgroud) ios ×7
iphone ×5
ios7 ×2
objective-c ×2
apple-watch ×1
content-type ×1
curl ×1
ios8 ×1
mapkit ×1
nsurlcache ×1
nsurlsession ×1
php ×1
ssl ×1
watchkit ×1
wget ×1
xcode7 ×1