UIWebView:我可以禁用任何网页内的JavaScript alert()吗?

我正在使用UIWebView加载一个URL。 在该网页的内部,它使用alert("whatever msg")作为JavaScript。 我的UIWebView将popup一个窗口,并显示警报消息。 有没有办法来禁用这种popup式窗口或JavaScript警报窗口?

Alamofire与自签证书/ ServerTrustPolicy

我想使用Alamofire通过https连接与我的服务器进行自我签名证书通信。 我的环境在本地主机上运行。 我试图连接,但是反应一直如下所示: Success: false Response String: nil 我用下面的代码完成了它: import Foundation import UIKit import Alamofire class MessageView: UITableViewController { let defaultManager: Alamofire.Manager = { let serverTrustPolicies: [String: ServerTrustPolicy] = [ "localhost": .DisableEvaluation ] let configuration = NSURLSessionConfiguration.defaultSessionConfiguration() configuration.HTTPAdditionalHeaders = Alamofire.Manager.defaultHTTPHeaders return Alamofire.Manager( configuration: configuration, serverTrustPolicyManager: ServerTrustPolicyManager(policies: serverTrustPolicies) ) }() override func viewDidLoad() { super.viewDidLoad() defaultManager […]

Facebook没有显示在UIActivityViewController,但叽叽喳喳做

我的iOS是8.1.2,我正在使用UIActivityViewController进行社交分享。 我点击一个button,并允许UIActivityViewController呈现 – (IBAction)UIActivityTypeButtonClick:(id)sender { NSString* text=@"I am sharing this text"; NSArray* sharedArray=@[text]; UIActivityViewController * activityVC=[[UIActivityViewController alloc]initWithActivityItems:sharedArray applicationActivities:nil]; activityVC.excludedActivityTypes=@[]; [self presentViewController:activityVC animated:YES completion:nil]; } 我正在得到这个 我得到消息 , 推特 , 邮件 , WhatsApp和更多button。 点击更多我得到这个。 FACEBOOK在哪里? 我有我的iPhone的Facebook应用程序,它是设置与我的ID太设置。 但Facebook从来没有出现在这里。 Twitter呢。 这是一个错误还是什么? 请build议 谢谢

indexPathForSelectedRow返回nil

我有一个UIVableViewController与我试图得到当前选定的行的segue: -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{ if([[segue identifier] isEqualToString:@"EditFilterElementSegue"]){ // Get the element that was clicked and pass it to the view controller for display NSIndexPath *selectedIndexPath = [self.tableView indexPathForSelectedRow]; Element *element = [fetchedResultsController objectAtIndexPath:selectedIndexPath]; FilterElementTableViewController *vc = segue.destinationViewController; vc.filter = filter; vc.element = element; } } 问题是indexPathForSelectedRow返回nil。 文档说,如果索引path无效,返回nil。 如果我添加: [self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:YES scrollPosition:0]; selectedIndexPath […]

在iOS应用程序中收听所有触摸事件

是否有可能以某种方式聆听并捕捉应用程序中发生的所有触摸事件? 我正在开发的应用程序将用于展示厅和信息亭,因此,如果在给定的几分钟内没有收到任何触摸,我将回到应用程序的开始部分。 一种屏保function,如果你愿意。 我打算通过在后台运行一个计时器来实现这一点,应该重置和重新启动每次触摸事件发生在应用程序的某个地方。 但是我怎样才能听触摸事件? 任何想法或build议?

如何以编程方式在UICollectionVIew中插入单元格?

我有一个UICollectionView ,它工作正常,但我想以编程方式添加一些UICollectionViewCells项目到集合视图。 那么我怎么能做到这一点呢? 为了进一步阐明:当我以编程的方式说我的意思是插入一个单元格在运行时,当一个动作被激发,而不是当应用程序被加载(使用viewDidLoad方法)。 我知道模型何时被更新,并且在insertItemsAtIndexPaths:方法中调用了UICollectionView 。 它应该创build一个新的单元格,但不是这样做的,这是抛出一个错误。

创build具有相同名称的串行队列的两个对象共享同一个队列

不确定的行为,因为我怀疑我正在陷入僵局, 我有一个类与多个对象 – 每个对象创build一个具有相同名称的队列。 我不确定GCD是否在对象之间重复使用相同的队列,或者它们是否共享相同的名称。 例如 @interface MyClass -(void)doSomeWork @property (nonatomic,strong) dispatch_queue_t myQueue; @end @implementation MyClass -(id)init { self = [super init]; self.myQueue = dispatch_queue_create("MyQueue",DISPATCH_QUEUE_SERIAL); return self; } -(void)doSomeWork { dispatch_async(self.myQueue,^{ // some long running work }); } @end @interface SomeClassWhichCreatesALotOfObjects @end @implementation SomeClassWhichCreatesALotOfObjects -(void)someMethod { for(int i = 0; i < 10000; i++) { […]

Swift中的自定义Segue

@objc(SEPushNoAnimationSegue) class SEPushNoAnimationSegue: UIStoryboardSegue { override func perform () { self.sourceViewController.navigationController.pushViewController(self.destinationViewController, animated:false) } } 在上面的代码中,我有两个问题:1)。 它有一个编译错误:'UINavigationController!' 没有名为“pushViewController”的成员 但在那个类中,它有一个pushViewController方法。 2)。 我必须添加注释:@objc(SEPushNoAnimationSegue),否则,在故事板中,它只识别随机生成的名称,如_tcxxxxSEPushNoAnimationSegue。 为什么这两个问题在这里发生?

如何find一种方法可能抛出并在Swift中捕获它们的错误

我正在使用NSFileManager.contentsOfDirectoryAtPath获取目录中的文件名数组。 我想使用新的do-try-catch语法来处理错误: do { let docsArray = try fileManager.contentsOfDirectoryAtPath(docsPath) } catch { // handle errors print(error) // this is the best I can currently do } 我docsPath一个错误可能是docsPath不存在,但我不知道如何捕捉这个错误。 而且我不知道可能发生的其他可能的错误。 文档示例 error handling文档有这样一个例子 enum VendingMachineError: ErrorType { case InvalidSelection case InsufficientFunds(centsNeeded: Int) case OutOfStock } 和 do { try vend(itemNamed: "Candy Bar") // Enjoy delicious snack } […]

任何方式来获取响应正文HTTP错误?

我碰到一个偶尔会抛出HTTP 403错误的API,响应主体可以以json的forms提供一些额外的信息,但是对于我来说,我似乎无法从Alamofire中获取信息响应对象。 如果我通过chrome访问API,我会看到开发者工具中的信息。 这是我的代码: Alamofire.request(mutableURLRequest).validate().responseJSON() { (response) in switch response.result { case .Success(let data): if let jsonResult = data as? NSDictionary { completion(jsonResult, error: nil) } else if let jsonArray = data as? NSArray { let jsonResult = ["array" : jsonArray] completion(jsonResult, error: nil) } case .Failure(let error): //error tells me 403 //response.result.data can't be […]