仅在属性存在时测试它?(Test a property only if it exists?)
如果响应没有
msgs[0]
属性,则以下测试会生成错误。if response.msgs[0] === "published" { ... }
错误是:
Uncaught TypeError: Cannot read property '0' of undefined
如何重写测试以生成错误? 如果没有
msgs[0]
属性,我希望测试评估为false
。The following test generates an error if the response does not have a
msgs[0]
property.if response.msgs[0] === "published" { ... }
The error is:
Uncaught TypeError: Cannot read property '0' of undefined
How can I rewrite the test to generate an error? If there is no
msgs[0]
property, I want the test to evaluate tofalse
.
原文:https://stackoverflow.com/questions/37543272
满意答案
你在哪里获得访问令牌fb添加后通知
[[NSNotificationCenter defaultCenter] postNotificationName:@“fbDidLogin”object:nil];
现在用于初始fb登录的方法是
-(void)fbLogin { [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(fbDidLogin) name:@"fbDidLogin" object:nil]; // some logic for intial fb login page }
另外在fbDidLogin方法中添加这个
- (void)fbDidLogin { [[NSNotificationCenter defaultCenter]removeObserver:self name:@"fbDidLogin" object:nil]; [self.switch setOn:YES animated:YES]; }
这里fbDIdLogin将在接收到令牌时立即被调用
如果访问令牌为零,则可以对fb登录失败执行类似的过程。
where u get access token for fb add post notification
[[NSNotificationCenter defaultCenter] postNotificationName:@"fbDidLogin" object:nil];
Now the method for intial fb login is
-(void)fbLogin { [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(fbDidLogin) name:@"fbDidLogin" object:nil]; // some logic for intial fb login page }
Also in fbDidLogin method add this
- (void)fbDidLogin { [[NSNotificationCenter defaultCenter]removeObserver:self name:@"fbDidLogin" object:nil]; [self.switch setOn:YES animated:YES]; }
Here fbDIdLogin will be called as soon as access token is recieved
Similar process can be done for fb login failed if access token is nil .
相关问答
更多iPhone - 在Facebook登录后,UISwitch的状态未设置为“On” - (void)fbDidLogin方法(iPhone - After facebook login, status of UISwitch is not setting to 'On' in -(void)fbDidLogin method)
facebook fbDidLogin appdelegate外面(facebook fbDidLogin outside appdelegate)
具有UISwitch功能的iPhone UIButton(iPhone UIButton with UISwitch functionality)
Facebook在应用程序内执行(无需在Safari或本机应用程序中打开)(Facebook Implementation within app (without opening in safari or native app))
是否有可能在iPhone的设置中检测Facebook登录状态?(Is it possible to detect facebook log in status in iphone's settings?)
UISwitch不返回其当前状态(开/关)(UISwitch not returning its current state (on/off))
UISwitch无法正常工作(UISwitch is not working properly)
向UISwitch添加行为(Add behaviour to UISwitch)
Facebook iOS登录 - 未调用委托方法(Facebook iOS Login - Delegate methods not being called)
iphone - 使用UISwitch(iphone - using a UISwitch)
相关文章
更多could not find system property or JNDI
mybatis There is no getter for property named 'xx' in 'class java.lang.String
Hibernate 异常之:associate a collection with two ...
[转]So You Want To Be A Producer
Becoming a data scientist
Fading Like a Flower - Roxette
A Great List of Windows Tools
Drupal Forums instead of phpBB or vBulletin: A casestudy
每日英语:Man Without a Country
HTML 超链接(a标签、锚)
最新问答
更多获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
如何通过引用返回对象?(How is returning an object by reference possible?)
矩阵如何存储在内存中?(How are matrices stored in memory?)
每个请求的Java新会话?(Java New Session For Each Request?)
css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
xcode语法颜色编码解释?(xcode syntax color coding explained?)
在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
Copyright ©2023 peixunduo.com All Rights Reserved.粤ICP备14003112号
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们(neng862121861#163.com),本站将尽快处理。谢谢合作!