Apple today seeded a sixth beta of OS X Yosemite 10.10.2 to developers, just a week after seeding the fifth beta of OS X 10.10.2, and two months after seeding the first beta.
The new beta, build 14C106a, is available through the Software Update mechanism in the Mac App Store and through the Mac Dev Center.
As with previous betas, Apple asks developers to focus testing on Wi-Fi, Mail, Bluetooth, and VoiceOver. Many Yosemite users have had some ongoing problems with Wi-Fi since the new OS was first launched in October, and a November 10.10.1 update did not resolve all of the lingering issues.
Month: January 2015
Dealing with NSInternalInconsistencyException when removing UITable row
Stupid situation, today I wanted to test deleteRowsAtIndexPaths method from UITable withRowAnimation:UITableViewRowAnimationFade – just to check how it will look, did not wanted to remove my db record and add it every run, but always I was getting:
'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (4) must be equal to the number of rows contained in that section before the update (4), plus or minus the number of rows inserted or deleted from that section (0 inserted, 1 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).'
The reason was simple – in my array I still had removed entry and it caused such exception. So if you want to test something and don’t want to remove db record, you need to remove it at least from array where UITable data is stored, in my case:
[myArray removeObjectAtIndex:myRow];
just helped, and in case anyway will look for a way to remove table row while having only its index:
NSIndexPath * path= [NSIndexPath indexPathForRow:myRow inSection:0]; [tblSeries deleteRowsAtIndexPaths:[NSArray arrayWithObject:path] withRowAnimation:UITableViewRowAnimationFade];
And thats all, you don’t need (or even you cannot) use reloadData method. Of course if your table has sections, you need to put proper value as “inSection” argument. The simples and most elegant way is to extend UITableViewCell and add your properties for holding row and section:
@interface MyCell : UITableViewCell @property int row; @property int section; @end
Yosemite 10.10.2 Build 14C99d is now available to developers
Apple today seeded a fifth beta of OS X Yosemite 10.10.2 to developers, just one week after seeding the fourth beta of OS X 10.10.2 and nearly two months after seeding the first beta.
The new beta, build 14C99d, is available through the Software Update mechanism in the Mac App Store and through the Mac Dev Center.
As with previous betas, Apple asks developers to focus testing on Wi-Fi, Mail, and VoiceOver. Many Yosemite users have had some ongoing problems with Wi-Fi since the new OS was first launched in October, and a November 10.10.1 update did not resolve all of the lingering issues.
Send pdf automatically when invoice is created in Magento
It is a bit different then method showed in previous post – this time its not transactional email sent at demand, but we will catch event fired after invoice is generated. So (I suppose you have your module already) in etc/config.xml add:
<global> <events> <sales_order_invoice_save_after> <observers> <yourvendor_yourmodule_invoice_observer> <class>YourVendor_YourModule_Model_Observer</class> <method>sendInvoice</method> </yourvendor_yourmodule_invoice_observer> </observers> </sales_order_invoice_save_after> </events> </global>
Then create your class at app/code/local/YourVendor/YourModule/Model/Observer.php (or use existing one) and add new method:
public function sendInvoice($observer) { try { /* @var $order Magento_Sales_Model_Order_Invoice */ $invoice = $observer->getEvent()->getInvoice(); $invoice->sendEmail(); } catch (Mage_Core_Exception $e) { Mage::log("Error: " . $e->getMessage()); } return $this; }
And invoice will be attached to email defined at:
Quicktip: How to send PDF invoice via transactional email in Magento?
Seems to be complex, but its not that bad:
$orderModel = Mage::getModel('sales/order')->load($myOrderId); $invoices = $orderModel->getInvoiceCollection(); $invoicesSet = array(); foreach ($invoices as $_invoice) { array_push($invoicesSet, $_invoice); } $pdf = Mage::getModel('sales/order_pdf_invoice')->getPdf($invoicesSet); $file = $pdf->render(); $senderName = Mage::getStoreConfig('trans_email/ident_support/name'); $senderEmail = Mage::getStoreConfig('trans_email/ident_support/email'); $sender = array('name' => $senderName, 'email' => $senderEmail); $templateId = 'sales_email_order_template'; $emailTemplate = Mage::getModel('core/email_template')->loadByCode($templateId); $vars = array('user_name' => 'some user name', 'product_name' => 'some product name'); $emailTemplate->getProcessedTemplate($vars); $emailTemplate->setSenderEmail($senderEmail); $emailTemplate->setSenderName($senderName); $attachment = $emailTemplate->getMail()->createAttachment($file); $attachment->type = 'application/pdf'; $attachment->filename = 'invoice.pdf'; $res = $emailTemplate->sendTransactional($templateId, $sender, 'user@example.com', "Admin", $vars);
About $vars variable – in this one you can put everything which is set inside email template as variables.
Fourth iOS 8.2 Beta is available to developers
Apple today seeded the fourth beta of iOS 8.2 to developers, nearly a month after seeding the third beta and more than two months after releasing the first iOS 8.2 beta.
The beta, build 12D5461b, is available immediately to registered developers as an over-the-air update and it can also be downloaded from the iOS Developer Center. Today’s update also includes Xcode 6.2 beta 4 with WatchKit.
iOS 8.2 includes the WatchKit SDK, allowing developers to create apps, Glances, and notifications for Apple’s upcoming wearable device ahead of its 2015 launch. The first iOS 8.2 beta, with WatchKit SDK and developer documentation, revealed several new details about the Apple Watch, including its heavy reliance on the iPhone and the different types of content developers can create for the device.
The iOS 8.2 update has been widely expected to be released in conjunction with the launch of the Apple Watch and the fourth iOS 8.2 beta adds new evidence to support that theory.
In the Bluetooth section of the Settings menu on the iPhone, there’s now a mention of the Apple Watch, advising users to open the “Apple Watch app” to pair an iPhone with an Apple Watch. The Apple Watch iPhone app will likely be used to allow Apple Watch wearers to control settings on the device from their iPhones.
Tutorial: Custom UITable section header using Interface Builder
I saw a lot of tutorials about custom header/footer, or even custom section header, but they were creating controls programatically, in this tutorial I want to show how easy is to use Interface Builder to achive same result.
Apple Seeds OS X Yosemite 10.10.2 Build 14C94b
Apple today seeded a fourth beta of OS X 10.10.2 Yosemite to developers, nearly four weeks after the previous beta release.
The new beta, build 14C94b, is available through the Software Update mechanism in the Mac App Store and through the Mac Dev Center.
Apple continues to ask developers to focus their testing on Wi-Fi, Mail, and VoiceOver. Wi-Fi in particular has been an issue for some OS X Yosemite users since the operating system’s October launch, and OS X 10.10.1 released in November failed to resolve all of those problems.
FMDB and threaded update/select
FMDB is pretty cool but due to specific iOS behaviour while using threads, it can lead to unexpected results. First rule is – never use FMDB as singleton. Yes, if you’re coming from PHP it can be tempting as single db connection is common there. But consider such scenario:
- SELECT myfield FROM mytable WHERE id = 1; // let’s say this will give you “0” as result
- User pushed button in your app, which should change “myfield” to 1 and reload data
- So in push action you’re doing UPDATE mytable SET myfield = 1 WHERE id = 1;
- After this you’re calling something like [self reloadData]; and expected value for “myfield” is “1”, but instead you have still “0”
This happens becouse iOS locked your db and has local “snapshot” in which your “myfield” has value “0”. To prevent this all SELECT/UPDATE/INSERT operations should use FMDatabaseQueue. So your update method should looks like this:
-(void)switchMyfield:(NSString*)myid{ FMDatabaseQueue* queue = [FMDatabaseQueue databaseQueueWithPath:@"path/to/db.sqlite"]; [queue inDatabase:^(FMDatabase *db) { NSDictionary* currentData = [self getRecord:myid]; if([[currentData objectForKey:@"myfield"] intValue] == 0){ [db executeUpdateWithFormat:@"UPDATE mytable SET myfield = 1 WHERE id = %@", myid, nil]; }else{ [db executeUpdateWithFormat:@"UPDATE mytable SET myfield = 0 WHERE id = %@", myid, nil]; } }]; }
If you need to fetch some date you should use __block and just add columns to list as usual:
-(NSMutableArray*)fetchSomeData{ __block NSMutableArray* list = [[NSMutableArray alloc] init]; [queue inDatabase:^(FMDatabase *db) { NSString *sql = @"SELECT * FROM mytable WHERE myfield > 0"; FMResultSet *results = [db executeQuery:sql]; if(!results){ NSLog(@"%@", [db lastErrorMessage]); }else{ while([results next]) { [list addObject:[results resultDictionary]]; } } }]; return list; }