Sharing data between an iOS 8 share extension and main app

You should use NSUserDefaults like this: Save data: objc NSUserDefaults *shared = [[NSUserDefaults alloc] initWithSuiteName:@”group.yougroup”]; [shared setObject:object forKey:@”yourkey”]; [shared synchronize]; swift let defaults = UserDefaults(suiteName: “group.yourgroup”) defaults?.set(5.9, forKey: “yourKey”) Read data: objc NSUserDefaults *shared = [[NSUserDefaults alloc] initWithSuiteName:@”group.yougroup”]; id value = [shared valueForKey:@”yourkey”]; NSLog(@”%@”,value); swift let defaults = UserDefaults(suiteName: “group.yourgroup”) let x = defaults?.double(forKey: “yourKey”) … Read more

iOS 8 Custom Keyboard: Changing the Height

This is my code on Xcode 6.0 GM. Both orientations are supported. Update: Thanks to @SoftDesigner, we can eliminate the constraint conflict warning now. Warning: XIB and storyboard are not tested. It’s been reported by some folks that this does NOT work with XIB. KeyboardViewController.h #import <UIKit/UIKit.h> @interface KeyboardViewController : UIInputViewController @property (nonatomic) CGFloat portraitHeight; … Read more

openURL not work in Action Extension

This is what I used to do: UIWebView * webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)]; NSString *urlString = @”https://itunes.apple.com/us/app/watuu/id304697459″; NSString * content = [NSString stringWithFormat : @”<head><meta http-equiv=’refresh’ content=”0; URL=%@”></head>”, urlString]; [webView loadHTMLString:content baseURL:nil]; [self.view addSubview:webView]; [webView performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:2.0]; Please note that in this case I am instantiating this call from the … Read more

Communicating and persisting data between apps with App Groups

Another benefit to App Groups is the ability to share a NSUserDefaults database. This also works for App Extensions (notification center widgets, custom keyboards, etc). Initialize your NSUserDefaults object like this in all applications in the app group and they will share the database: Objective-C: [[NSUserDefaults alloc] initWithSuiteName:@”<group identifier>”]; Swift: NSUserDefaults(suiteName: “<group identifier>”) Keep in … Read more

tech