我一直在研究斯坦福iPhone编码课程,目前正在使用Twitter API.我想要做的是准确处理两个错误条件:一个用于用户名无效,另一个用于当设备当前未连接到互联网时.不幸的是,就目前而言,我能猜测的最好的是API的回报是否为零 - 这两种情况都是如此.
我正在寻找的是一行或两行代码,可以在尝试任何远程数据获取之前检查连接.我可以筛选Apple文档,但我想:为什么不把这个问题提交给你们,为了我的利益,也许是其他人的利益?
附加信息:在XCode中使用Objective-C和iPhone SDK.
我们正在创建一个依赖于其他命令来生成新数据库并构建其模式的命令.到目前为止,我们已经成功地读取了config.yml文件,添加了我们的新连接信息,并将文件写回来.在同一个命令中,我们然后尝试运行symfony命令来创建数据库和模式:update.这是我们遇到问题的地方.我们收到以下错误:
[InvalidArgumentException]名为"mynewdatabase"的Doctrine ORM Manager不存在.
如果我们第二次运行该命令则没有错误,因为更新的配置文件被新加载到应用程序中.如果我们在写入config.yml文件后手动运行doctrine命令,它也可以正常运行.
我们认为,在我们运行数据库创建和更新命令的命令中,它仍然使用存储在内存中的当前内核版本的config.yml/database.yml.我们尝试了许多不同的方法来重新初始化应用程序/内核配置(调用shutdown(),boot()等)而没有运气.这是代码:
namespace Test\MyBundle\Command;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Yaml\Yaml;
class GeneratorCommand extends ContainerAwareCommand
{
protected function configure()
{
$this
->setName('generate')
->setDescription('Create a new database.')
->addArgument('dbname', InputArgument::REQUIRED, 'The db name')
;
}
/*
example: php app/console generate mynewdatabase
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
//Without this, the doctrine commands will prematurely end execution
$this->getApplication()->setAutoExit(false);
//Open up app/config/config.yml
$yaml = Yaml::parse(file_get_contents($this->getContainer()->get('kernel')->getRootDir() .'/config/config.yml'));
//Take input dbname and use …Run Code Online (Sandbox Code Playgroud) 帮助,如果你能 -
情况:
http://foobar.com包含一个远程托管的javacript文件(http://boobar.com/stuff.js).
目标是从foobar.com上的远程托管的PHP脚本获取警报
我在stuff.js中尝试了以下代码:
$.ajax({
type: "GET",
url: "http://www.boobar.com/script.php?callback=?",
dataType: 'jsonp',
success: function(result) { alert(result); }
});
Run Code Online (Sandbox Code Playgroud)
没运气.
$.getJSON("http://www.boobar.com/script.php?jsonp=?",
function(data) { alert(data); }
);
Run Code Online (Sandbox Code Playgroud)
也没有运气.
在php方面,我尝试了以下两种方法:
return json_encode(array(0 => 'test'));
echo json_encode(array(0 => 'test'));
Run Code Online (Sandbox Code Playgroud)
在Firefox中我收到安全错误.我知道它认为我违反了安全模型.但是,根据jquery文档,我应该能够做到这一点.
这是代码:
for(int i = 0; i < personListViewController.peopleCount; i++) {
[NSThread detachNewThreadSelector:@selector(getPerson:) toTarget:self withObject:i];
}
Run Code Online (Sandbox Code Playgroud)
getPerson看起来像这样:
- (void)getPerson:(int)whichPerson { }
Run Code Online (Sandbox Code Playgroud)
当我构建它时,我得到以下结果:警告:传递'detachNewThreadSelector:toTarget:withObject:'的参数3使得整数指针没有强制转换
我想要做的就是通过detachNewThreadSelector将一个int传递给getPerson,我无法弄清楚如何让它除了一个对象指针之外的其他东西.我在这里错过了什么?
objective-c ×2
php ×2
ajax ×1
cocoa-touch ×1
doctrine-orm ×1
ios ×1
iphone ×1
javascript ×1
jquery ×1
symfony ×1
symfony-2.1 ×1
twitter ×1