Я хочу реализовать одну функциональность, как это делал мой коллега по Android.Ниже приведен фрагмент кода, и у меня возникли проблемы с преобразованием этого кода в target-c.Поэтому, пожалуйста, направьте меня в правильном направлении --- Спасибо
Вот фрагмент кода
public String createControlParams() {
controlParams_ = "";
String expiry = "";
String delayedDelivery = "";
String restricted = "";
String priorityIndicator = "";
String acknowledgement = "";
//Note - PMessage.PRIORITY_INDICATOR_WHITE is defined as Int like 1,2,3
if (priorityIndicator_ == PMessage.PRIORITY_INDICATOR_WHITE) {
expiryTimeText_ = "";
restrictBackup = false;
restrictForward_ = false;
readAcknowledgement_ = false;
}
if (expiryTimeText_ != null && expiryTimeText_.length() > 0) {
int exptime = Integer.parseInt(expiryTimeText_);
byte h = (byte) (exptime / 60);
byte m = (byte) (exptime % 60);
expiry = new String(new byte[]{'E', 0, h, m});//??? how to get this thing in objective-c
}
if (delayDelivery) {
long timeDifference;
long deliveryTime;
// Fix
// if (midlet_.getPlatform().equalsIgnoreCase("rim")) {
//// timeDifference = Calendar.getInstance().getTimeZone().getRawOffset();
//// deliveryTime = (dateField_.getTime() - (dateField_.getTime() % (24 * 60 * 60 * 1000))) + (24 * 60 * 60 * 1000) + deliverySetTime_ - timeDifference;//+timeDifference;//(((Integer) timeSpinner.getValue()).longValue() * 1000);
// deliveryTime = (dateField_.getTime() + deliverySetTime_);// - timeDifference;
// } else {
deliveryTime = dateField_.getTime() + deliverySetTime_;// - timeDifference;
// }
if (deliveryTime > (new Date().getTime() + 2000)) { // Added to_ make message as instant delivery as opposed to_ delayed delivery if the delivery time is set in past (Added 2 seconds for message processing time)
delayedDelivery = "D" + deliveryTime;
}
}
if (restrictBackup && restrictForward_) {
restricted = new String(new byte[]{'R', (byte) 3});
} else if (restrictForward_) {
restricted = new String(new byte[]{'R', (byte) 1});
} else if (restrictBackup) {
restricted = new String(new byte[]{'R', (byte) 2});
}
if (priorityIndicator_ == PMessage.PRIORITY_INDICATOR_RED) {
priorityIndicator = new String(new byte[]{'P', (byte) PMessage.PRIORITY_INDICATOR_RED});
} else if (priorityIndicator_ == PMessage.PRIORITY_INDICATOR_YELLOW) {
priorityIndicator = new String(new byte[]{'P', (byte) PMessage.PRIORITY_INDICATOR_YELLOW});
} else if (priorityIndicator_ == PMessage.PRIORITY_INDICATOR_GREEN) {
priorityIndicator = new String(new byte[]{'P', (byte) PMessage.PRIORITY_INDICATOR_GREEN});
} else if (priorityIndicator_ == PMessage.PRIORITY_INDICATOR_GRAY) {
priorityIndicator = new String(new byte[]{'P', (byte) PMessage.PRIORITY_INDICATOR_GRAY});
} else if (priorityIndicator_ == PMessage.PRIORITY_INDICATOR_WHITE) {
priorityIndicator = new String(new byte[]{'P', (byte) PMessage.PRIORITY_INDICATOR_WHITE});
}
if (readAcknowledgement_) {
acknowledgement = new String(new byte[]{'A', PMessage.ACK_READ});
}
controlParams_ = priorityIndicator;
if (!expiry.equals("") && expiry != null) {
controlParams_ += (byte) (-128) + expiry;
}
if (!delayedDelivery.equalsIgnoreCase("") && delayedDelivery != null) {
controlParams_ += (byte) (-128) + delayedDelivery;
}
if (!restricted.equalsIgnoreCase("") && restricted != null) {
controlParams_ += (byte) (-128) + restricted;
}
if (!acknowledgement.equalsIgnoreCase("") && acknowledgement != null) {
controlParams_ += (byte) (-128) + acknowledgement;
}
return controlParams_;
// System.out.println(controlParams_);
}
private void getDraftControlParms(String controlParams_) {
if (!controlParams_.equals("") && controlParams_ != null) {
String[] sysParams = Helpers.splitUsingStringDelim(controlParams_, String.valueOf((byte) (-128)));
try {
for (int i = 0; i < sysParams.length; i++) {
if (!sysParams[i].equals("") && sysParams[i] != null) {
if (sysParams[i].substring(0, 1).equalsIgnoreCase("P")) {
priorityIndicator_ = (int) sysParams[i].getBytes()[1];
}
if (sysParams[i].substring(0, 1).equalsIgnoreCase("E")) {
int expiryFirstByte_ = sysParams[i].getBytes()[2];
int expirySecondByte_ =sysParams[i].getBytes()[3];
int expiryTime=(expiryFirstByte_ * 60) + (expirySecondByte_);
expiryMinutesField_.setText(expiryTime+"");
expiryTimeText_ = expiryMinutesField_.getText();
}
if (sysParams[i].substring(0, 1).equalsIgnoreCase("R")) {
int restrictedByte_ = (byte) sysParams[i].getBytes()[1];
if(restrictedByte_==1){
restrictForward_ = true;
restrictBackup = false;
}else if(restrictedByte_==2){
restrictForward_ = false;
restrictBackup = true;
}else{
restrictForward_ = true;
restrictBackup = true;
}
}
if (sysParams[i].substring(0, 1).equalsIgnoreCase("A")) {
readAcknowledgement_ = true;
}
}
switch (priorityIndicator_) {
case PMessage.PRIORITY_INDICATOR_RED: {
counter.getStyle().setBgColor(0xfe0002);
counter.getStyle().setBgTransparency(255);
break;
}
case PMessage.PRIORITY_INDICATOR_YELLOW: {
counter.getStyle().setBgColor(0xffff00);
counter.getStyle().setBgTransparency(255);
break;
}
case PMessage.PRIORITY_INDICATOR_GREEN: {
counter.getStyle().setBgColor(0x80ff00);
counter.getStyle().setBgTransparency(255);
break;
}
case PMessage.PRIORITY_INDICATOR_GRAY: {
counter.getStyle().setBgColor(0x919594);
counter.getStyle().setBgTransparency(255);
break;
}
case PMessage.PRIORITY_INDICATOR_WHITE: {
counter.getStyle().setBgColor(0xffffff);
counter.getStyle().setBgTransparency(255);
break;
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}