My devices:
iPad Mini (latest), iOS 8 dp5.
Macbook Air, Yosemite dp5.
I have Handoff working between the two above devices. Safari, Mail, Messages, Calendar, etc. all handoff with no problems.
I can even handoff between my website on the Air and my native app on the iPad.
What I can't do yet is go from my native app on the iPad to my website in Safari on my Air.
For the first view controller that loads in my native app, I have this:
- (void)viewDidLoad
{
[super viewDidLoad];
NSUserActivity *webHandoff = [[NSUserActivity alloc] initWithActivityType:#"com.myApp.iphone.staging.webbrowsing"];
webHandoff.webpageURL = [NSURL URLWithString:#"http://staging.myApp.com"];
[webHandoff becomeCurrent];
}
In my app's Info.plist file, I have this:
<key>NSUserActivityTypes</key>
<array>
<string>com.myApp.iphone.staging.webbrowsing</string>
</array>
Am I missing something or do I have something configured incorrectly?
Thanks for any help!
I made two significant changes to my code:
1) configure/destroy and set the NSUserActivity object in viewDidAppear/disappear as opposed to viewDidLoad:
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
NSUserActivity *webHandoff = [[NSUserActivity alloc] initWithActivityType:#"com.myApp.iphone.staging.web-browsing"];
webHandoff.webpageURL = self.handoffWebpageURL;
[self setUserActivity:webHandoff];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
[self.userActivity invalidate];
}
2) Since UIViewController is a subclass of UIResponder and UIResponders have a userActivity property, instead of calling [webHandoff becomeCurrent] I simply called [self setUserActivity:webHandoff];
Not sure why moving it out of viewDidLoad had any impact, and not sure why I need to set it to the viewController's instance of NSUserActivity, but the changes above give me a solid and reliable handoff experience throughout my entire app.
Related
- (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(NSString *)type
{
[[UIApplication sharedApplication] presentLocalNotificationNow:notification];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
viewcontroller2 *historyVC = [storyboard instantiateViewControllerWithIdentifier: #"second"];
self.window.rootViewController = historyVC;
[self.window makeKeyAndVisible];
}
My app not opening from background to foreground but as per apple doc they said app will be come foreground.
The following method
- pushRegistry:didUpdatePushCredentials:forType:
is invoked when push notification is received.
until and unless user launches the app, we cant open the app.
when u open app. make preferences to show your respective view controller.
Using push kit, newer your app will get open automatically. that would not come to foreground from background or terminated state.
Your app will only gets active in background mode for some 30 seconds and you would be able to do rest of work whichever is needed. ( For example setting some values in Database etc )
I'm developing a Cocoa App and I noticed NSBundle loadNibNamed is deprecated.
I'm trying to use a Sheet to show some config options. I'm using an AppController and the Config Sheet is a NIB created separately.
This is my code.
- (IBAction)showConfig:(id)sender{
if (!_config) {
[NSBundle loadNibNamed:#"Config" owner:self];
}
[NSApp beginSheet:self.config modalForWindow:[[NSApp delegate] window] modalDelegate:self didEndSelector:NULL contextInfo:NULL];
}
Using that code, the config Sheet opens and closes perfectly.
When I switch this [NSBundle loadNibNamed:#"Config" owner:self]; to [[NSBundle mainBundle] loadNibNamed:#"Config" owner:self topLevelObjects:nil]; the config Sheet still works fine.
My real problem is when I want to close it. The app crashes throwing this error:
Thread 1:EXC_BAD_ACCESS (code=EXC_I386_GPFLT)
This is my IBAction to close the config Sheet.
- (IBAction)closeConfig:(id)sender{
[NSApp endSheet:self.config];
[self.config close];
self.config = nil;
}
Once I skip the deprecated line, what do I need to do to close the config sheet correctly?
I'm running Yosemite and Xcode 6.4.
Is the window property in your app delegate class weak? If so, see this answer. The not-deprecated method that you are now using requires your controller to have strong references to the top level objects.
Normally, when I use mfmailcomposeviewcontroller like so:
if ([MFMailComposeViewController canSendMail])
{
MFMailComposeViewController *mcvc = [[MFMailComposeViewController alloc] init];
mcvc.mailComposeDelegate = self;
[mcvc setSubject:#"Check out these diamonds!"];
[self presentModalViewController:mcvc animated:YES];
[mcvc release];
}
And I am now getting this error on iOS 6:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException',
reason: 'Could not load NIB in bundle: 'NSBundle </Users/ericshorr/Library/Application Support/iPhone Simulator/6.0/Applications/7904C2AD-23E1-4211-B5FA-A1F03CB3A875/SDE Group Diamonds.app> (loaded)' with name 'MFMailComposeInternalViewController''
Because you need to setup a mail account in your iPad to be able to send mails in iOS 6. Go to Mail, Contacts, Calenders in Settings, then add a mail account.
I had a similar issue recently where I added a category to UIViewController, so that I could override init and append an additional modifier to the nib name. Like so...
self = [self initWithNibName:[nibName stringByAppendingString:#"_modifier"] bundle:nil];
Although the UIViewController category was not #imported in the class that was attempting to launch the MFMailComposeViewController, it was imported in the header of a different class that was being added as a child view controller. Hence, the MFMailComposeViewController was trying to find a NIB with name: MFMailComposeInternalViewController_modifier.
Seems obvious in hindsight but this was a nightmare to catch, so I thought I'd add it here as a possible solution, for anyone else who runs in to a similar situation.
I am building a web browser in Xcode cocoa application, using the interface builder. I have it all working when it comes to typing in web address and clicking go.
but I would like for it to automatically load a web page instead of seeing white when I open my project, I looked in inspector to see if you can set a specific web address but I couldn't find anything to do this.
How about if you load the URL that you would like in the viewdidload function:
- (void)viewDidLoad {
[super viewDidLoad];
NSURL *targetURL = [NSURL fileURLWithPath:WebsitePath];
NSURLRequest *WebRequest = [NSURLRequest requestWithURL:targetURL];
[self.WebViewer loadRequest:WebRequest];
self.WebViewer.scalesPageToFit = YES;
}
Maybe you can try to load the WebView when the application finish launching,just add the URL Request in the applicationDidFinishLauching parameter,else if your WebView is on the MainView you can add a loadingScreen that appear while the webView is loading!
Lucky!
I'm trying to make a mac app using the apple developer tools, specifically xcode. I'm basically imbedding my website into in in a sort of iTunes-esque way- side bar at right, user clicks a button on side bar and webview web page changes. Problem is I'm having trouble trying to get the button to load a specific URL into the webview.
WebView* webView = [[WebView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)];
NSString *urlAddress = #”http://www.example.com”;
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];
So you first get the url as a string, turn it into an NSURL object, and then into an NSURLRequest object and finally give that to the webview object to load. You could also do this with a webview created in Interface Builder by ommiting the first line (where the webview is being initialised) and make sure you add the webView property to the viewcontroller as an IBOutlet and connecting it to the webview in Interface Builder.
Edit: It seems I was using iPhone syntax for the webview. Loading a url on a mac webview however is still similar, so all I've changed is the class name.