Transfer iOS service from phone to macbook safari / chrome
I want to send a url from my application to open it in my laptop's web browser using handover. I have added an activity type to my application NSUserActivityTypes
. here is my code:
- (void)startHandoff {
NSUserActivity *activity = [[NSUserActivity alloc] initWithActivityType:@"com.me.browse"];
activity.webpageURL = [NSURL URLWithString:_wakeUrl];
[activity becomeCurrent];
}
It doesn't seem to show up on my dock - do you need a special Activity Type
one if you want to use safari?
+3
source to share
1 answer
Ok after the tests, it seems like you need to declare NSUserActivity
as an instance variable:
So this doesn't work:
@interface TestViewController () {
}
@end
@implementation TestViewController
- (void)viewDidLoad {
[super viewDidLoad];
//init hand off
NSUserActivity *activity = [[NSUserActivity alloc] initWithActivityType:@"com.app.browse"];
activity.webpageURL = [NSURL URLWithString:@"http://www.stackoverflow.com"];
[activity becomeCurrent];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
But this works great:
@interface TestViewController () {
NSUserActivity *activity;
}
@end
@implementation TestViewController
- (void)viewDidLoad {
[super viewDidLoad];
//init hand off
activity = [[NSUserActivity alloc] initWithActivityType:@"com.app.browse"];
activity.webpageURL = [NSURL URLWithString:@"http://www.stackoverflow.com"];
[activity becomeCurrent];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
I don't know why, although I'm studying it now
+2
source to share