Epson TM-T88V-i print only once - ios

I've a problem with an Epson TM-T88V-i printer, I can print the first time but after I receive always a EPOS2_ERR_CONNECT error.
I use the example in the SDK and it has this problem.
This is the code:
int result = EPOS2_SUCCESS;
if (self.printer == nil) {
return NO;
}
result = [self.printer connect:#"TCP:192.168.1.15" timeout:EPOS2_PARAM_DEFAULT];
if (result != EPOS2_SUCCESS) {
return NO;
}
result = [self.printer beginTransaction];
if (result != EPOS2_SUCCESS) {
[self.printer disconnect];
return NO;
}
After the first time it goes in the if after the connect method with the EPOS2_ERR_CONNECT
I must restart the printer to reprint something.

I had the same problem months ago...
For the TM-T88V-i printers you must connect with another syntax:
use <connection type>:<identifier>[<device ID>] instead of <connection type>:<identifier>
So your code is something like this:
result = [self.printer connect:#"TCP:192.168.1.15[local_printer]" timeout:EPOS2_PARAM_DEFAULT];
N.B. local_printer is the default identifier.

Related

How can I use the result returned in a delegate method to fire a callback in React-Native (iOS)

So I'm in a bit of a pickle here...
I'm creating an application that requires me to use an awkward SDK for a specific hardware api - and to get the status of anything, rather than return a value it fires off a delegate method where the value is accessible there as an argument for the delegate method. This is making callbacks to React-Native a challenge.
Here is my basic method being called from React:
RCT_EXPORT_METHOD(openSirenAlarm: (RCTResponseSenderBlock) callback)
{
cameraControl.cameraSiren.delegate = self;
[cameraControl.cameraSiren playCameraSiren];
callback(#[#(error), #(response)]);
}
RCT_EXPORT_METHOD(closeSirenAlarm: (RCTResponseSenderBlock) callback)
{
cameraControl.cameraSiren.delegate = self;
[cameraControl.cameraSiren stopCameraSiren];
callback(#[#(error), #(response)]);
}
And here are the delegate methods provided in the SDK:
#pragma mark CameraSirenDelegate
- (void) cameraSiren:(CameraSiren *)cameraSiren stopResult:(ENUM_APP_RESULT)result
{
NSLog(#"stop result: %u", result);
if (result == RESULT_SUCCESS)
{
NSLog(#"stop success");
error = 0;
response = 1;
}
else
{
error = 1;
response = 0;
}
}
- (void) cameraSiren:(CameraSiren *)cameraSiren playResult:(ENUM_APP_RESULT)result
{
NSLog(#"start result: %u", result);
if (result == RESULT_SUCCESS)
{
NSLog(#"start success");
error = 0;
response = 1;
}
else
{
error = 1;
response = 0;
}
}
I'm having a couple issues:
As you can see, I'm setting the error result in the delegate methods, but the callback fires right away (including before they're even set the first time) - so at best they're one action behind in terms of information.
I've played with RCTEventEmitters but I find them to be generally sloppy and unreliable - generally firing at least twice and causing me a bit of a headache (if this is a common thing that anyone can help me with I'd gladly use emission).
Is there an obvious way to do this that I'm missing, or a smarter design pattern to handle this?

MPTweakValue without internet

I try to implement Mixpanel's tweaks into my app for A/B testing. This is my code:
if (MPTweakValue(kFeaturedOffersTweak, NO)) {
return MenuItemRowHeight;
}
else {
return 0;
}
On the first lunch everything is OK and tweak value is YES. Then I switch off internet on my iPhone, open run again and tweak value is NO.
What is correct way to use Mixpanel's tweak without internet?
So, I created my custom manager, where I implemented tweaks' persistency.
Please, let me know, if you have better solution.
My code:
-(void)initManager {
[[Mixpanel sharedInstance] joinExperimentsWithCallback:^{
USE_SETTINGS;
SETTINGS_SETBOOL(kPreferredPartnersTweak, MPTweakValue(kPreferredPartnersTweak, NO));
SYNCHRONIZE_SETTINGS;
//===
SEND_NOTIF(kTweaksUpdated, nil);
}];
}
-(BOOL)getTweakWithName:(NSString*)tweakName {
BOOL result = NO;
//===
USE_SETTINGS;
if (SETTINGS_BOOL(tweakName)) {
result = SETTINGS_BOOL(tweakName);
}
else {
result = MPTweakValue(kPreferredPartnersTweak, NO);
}
//===
return result;
}
USE_SETTINGS, SETTINGS_BOOL, SYNCHRONIZE_SETTINGS is my macros wrappers for working with NSUserDefaults.

How to check if an object is nil in Objective-C? [duplicate]

This question already has answers here:
Testing for nil in Objective-C -- if(x != nil) vs if(x)
(4 answers)
Closed 7 years ago.
So I know this seems pretty basic but it doesn't seem to be working for some reason. I have the following code.
Target *t = self.skill.target;
if (![t isEqual:nil]) {
NSLog(#"Not nil");
}
I tried this and it comes up as not nil everytime which is great except for when t should actually be nil. I even tried putting variation into the code like so and my t is still coming up as not nil for some reason. Am I doing something wrong? :\
Target *t = self.skill.target;
t = nil;
if (![t isEqual:nil]) {
NSLog(#"Not nil");
}
You can do it normally just by checking the object itself. There is also a good explanation on NSHipster for NSNull.
if( myObject ){
// do something if object isn't nil
} else {
// initialize object and do something
}
otherwise just use
if( myObject == nil ){
}
Target *t = self.skill.target;
t = nil;
if (t) {
NSLog(#"t is Not nil");
}
if (!t) {
NSLog(#"t is nil");
}
As this answer says:
Any message to nil will return a result which is the equivalent to 0 for the type requested. Since the 0 for a boolean is NO, that is the result.
So, a nil object is special. you can't compare it using the isEqual method. you should compare it without sending it a message, like this:
if (t)
{
}
or simply:
if (t != nil)
{
}
The if operation checks nillable so this should works:
Target *t = self.skill.target;
if (t) {
NSLog(#"Not nil");
}else{
NSLog(#"nil");
}
Hope it helps.

If statement not calling all methods returning BOOL

I have code like this:
-(IBAction)send {
if ([self isCorrect1] && [self isCorrect2] && ...) {
[self sendRequest];
}
}
-(BOOL)isCorrect1 {
...
}
-(BOOL)isCorrect2 {
...
}
Every isCorrect method is checking some condition showing some message in the view and returning result of the checking. I noticed that if first condition is false it will only show error message for the first method (and I need all of them to be checked) and no breakpoint is triggered inside these methods. I thought it was some kind of LLVM optimization so I created code like this:
-(IBAction)send {
BOOL correct = [self isCorrect1];
correct = correct && [self isCorrect2];
...
if (correct) {
[self sendRequest];
}
}
And is still not working correctly. Do I have to create new BOOL variable to store result for the check or is there some other way?
Since the first condition is evaluated to false, it won't check for the rest of the conditions and will go to the else part straightaway.
Try this.
BOOL finalResult = [self isCorrect1];
finalResult = [self isCorrect2] && finalResult;
finalResult = [self isCorrect3] && finalResult;
finalResult = [self isCorrect4] && finalResult;
...
if (finalResult) {
}
This will go through all of the isCorrect tests and will let you know if it passed all of them in the end or not.
The behaviour you see is the expected behaviour of the &&, namely, it "short-circuits" the evaluation, if it can determine the result in advance, before having evaluated all conditions:
expression-yielding-false && something-else
The result of the above is completely determined by the first part; regardless of what the second operand yields, the final result is false. This allows you to write something like:
if (obj != null && obj->count == 3)
{
...
}
If the && did not have the short-circuit behaviour, you'd have to write
if (obj != null)
{
if (obj->count == 3)
{
...
}
}
The || has a similar behaviour. In case of
something-yielding-true || anything
the right-hand side cannot affect the result value, as the left-hand side already returned true.
One possible work-around would be:
int succeeses = 0;
succeesses += [self isCorrect1]? 1 : 0;
succeesses += [self isCorrect2]? 1 : 0;
succeesses += [self isCorrect3]? 1 : 0;
if (successes == 3)
{
// All tests did succeed
}
else
{
// At least one failed.
}
If you need to know, which tests passed, and which failed, you can try:
BOOL passed1 = [self isCorrect1];
BOOL passed2 = [self isCorrect2];
BOOL passed3 = [self isCorrect3];
if (passed1 && passed2 && passed3)
{
// All tests did succeed
}
else
{
// At least one failed.
}
A more dense version of the above would be
int passed = 0;
passed |= [self isCorrect1]? (1 << 0) : 0;
passed |= [self isCorrect2]? (1 << 1) : 0;
passed |= [self isCorrect3]? (1 << 2) : 0;
if (passed == 7)
{
// All tests did succeed
}
else
{
if (passed & (1 << 0))
{
// First test passed
}
else
{
// First test failed
}
if (passed & (1 << 1))
{
// Second test passed
}
else
{
// Second test failed
}
if (passed & (1 << 2))
{
// Third test passed
}
else
{
// Third test failed
}
}
which is simply a more occult formulation of the version with a boolean variable per test tried.

Facebook Share Dialog/Feed Dialog on iOS - how to know if share button or cancel button is tapped

I was trying to implement a Facebook share dialog in my iOS app. I tried both the Share Dialog
https://developers.facebook.com/ios/share-dialog/
and Feed dialog
https://developers.facebook.com/docs/howtos/feed-dialog-using-ios-sdk/
In both the cases I was able to actually share my content, but my problem is I cannot track whether the user actually "Shared" or "Cancel"ed out.
The links above show handlers (even comments are there) which gets fired if the user actually shares the content. But when the code is actually run, it always returns positive or in other words I'm not being able to distinguish if the cancel button was hit or the share button.
Please point me out if I'm missing out anything, or if anyone else has faced the same issue.
Thanks,
Updating just in case this helps anyone, the following link finally worked for me:
https://developers.facebook.com/docs/howtos/ios-6/#nativepostcontroller
Though it had it's limitations (doesn't run on iOS < 6), but it successfully returns me when the user cancels out the dialog. Here's the code I used:
BOOL displayedNativeDialog = [FBDialogs presentOSIntegratedShareDialogModallyFrom:self
initialText:[NSString stringWithFormat:#"%#", url]
image:nil
url:url
handler:^(FBOSIntegratedShareDialogResult result, NSError *error) {
if(result == 0)
{
//Fire our callback
}
else{
NSLog(#"USER CANCELLED");
}
}];
Here's how to get the explicit result on your console.
FBDialogs.PresentShareDialog(myAction,"altimeterthree:share","flight",(call, results, error) => {
if(call != null)show("Call = " + call.ToString());
if(results != null)Console.WriteLine("Results = "+results.ToString());
if(error != null)Console.WriteLine("Error = "+FBErrorUtility.UserMessage(error));
});
Here's what the console output looks like. Notice that the result is also in the call info.
2014-05-11 10:09:26.067 AltimeterThree[18988:60b] Call = <FBAppCall: 0x19e02350, ID: 4589F102-3D11-40D5-BC95-1A1852B341AC
dialogData: <FBDialogsData: 0x19e04e20, method: ogshare
arguments: {
action = {
flight = {
data = {
};
description = "my description";
"fbsdk:create_object" = 1;
id = 1413672752238899;
image = (
{
url = "<UIImage: 0x147f9180>";
"user_generated" = true;
}
);
title = "Flight 23";
type = "altimeterthree:flight";
url = "http://http://samples.ogp.me/1413756595563848";
};
};
actionType = "altimeterthree:share";
previewPropertyName = flight;
}
results: {
completionGesture = cancel;
didComplete = 1;
}>
>
2014-05-11 10:09:26.070 AltimeterThree[18988:60b] Results = {
completionGesture = cancel;
didComplete = 1;
}

Resources