仅在属性存在时测试它?(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 .
相关问答
更多-
你在哪里获得访问令牌fb添加后通知 [[NSNotificationCenter defaultCenter] postNotificationName:@“fbDidLogin”object:nil]; 现在用于初始fb登录的方法是 -(void)fbLogin { [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(fbDidLogin) name:@"fbDidLogin" object:nil]; // ...
-
您可以从App Delegate发布通知,如下所示: - (void)fbDidLogin { [[NSNotificationCenter defaultCenter] postNotificationName:@"FBDidLoginCalled" object:nil]; } 然后在你的其他课堂上: - (void)loginFacebook { if (![facebook isSessionValid]) { [[NSNotificationCenter def ...
-
UIButton已经支持“切换”功能。 只需在Interface Builder中为“Selected State Configuration”选择不同的图像,并使用UIButton的selected属性来切换其状态。 UIButton already supports a "switch" functionality. Just set a different image in Interface Builder for the "Selected State Configuration", and us ...
-
在Facebook iOS SDK中,您可以编辑Facebook.m的授权方法,并将safariAuth和authorizeWithFBAppAuth设置为no,以便它执行Facebook连接样式弹出式登录。 In the Facebook iOS SDK, you can edit Facebook.m's authorize method and set safariAuth and authorizeWithFBAppAuth both to no so that it does the Facebo ...
-
是否有可能在iPhone的设置中检测Facebook登录状态?(Is it possible to detect facebook log in status in iphone's settings?)[2024-03-02]
以下将告诉你。 它会提示用户许可,但只有在iOS设置中启用了Facebook的情况下。 查看返回的错误代码以区分不同的失败情况。 将“YOUR_FACEBOOK_APPID”替换为您的Facebook应用的ID。 ACAccountStore *accountStore = [[ACAccountStore alloc] init]; ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccou ... -
用此代码替换代码。 并作为值更改控制事件再次与开关连接。 - (IBAction) sanitySwitch:(id)sender { if ([sender isOn]) { NSLog(@"SanityCheck ENABLED"); sanityCheck = YES; } else { NSLog(@"SanityCheck DISABLED"); sanityCheck = NO; } } Repl ...
-
UISwitch无法正常工作(UISwitch is not working properly)[2022-08-21]
正如上面提到的@ILideTau,你不应该直接使用UISwitch状态,而只是创建一个Bool变量,它将保持你的开关状态,并在你更改didSet {}闭包中的状态时更新UI: @IBOutlet weak var interestedInSwitch: UISwitch! var interstedInState: Bool = false { didSet { interestedInSwitch.on = interstedInState } } func update ... -
向UISwitch添加行为(Add behaviour to UISwitch)[2022-06-17]
您只希望在调用setFrame:时更改frame属性。 尝试编写一个覆盖setFrame的UISwitch类:一个类将由所有子类继承,并且因为setFrame:是从UIView继承的,并且未在UISwitch中声明,所以可以覆盖setter。 这样的事可能 - // UISwitch+UISwitchAdditions.h #import@interface UISwitch (UISwitchAdditions) - (void)setFrame:(CGRect)fr ... -
糟糕,我刚刚意识到application: handleOpenURL: method是一个iOS应用程序委托方法。 我在其中一个UIViewControllers中使用过它。 将它移动到正确的位置,它的工作原理。 Oops, I've just realized the application: handleOpenURL: method is an iOS application delegate method. I had it in one of my UIViewControllers. Move ...
-
iphone - 使用UISwitch(iphone - using a UISwitch)[2022-07-29]
我认为你应该按下自定义的“是”和“否”按钮。 通过这种方式,您可以更好地控制设计,并且可以避免Apple拒绝。 I think you should make custom "Yes" & "No" buttons that get selected when pushed. This way, you'll have more control on the design and you'll be safe from Apple rejection.