I have an application in VC sharing. After the user presses the button that causes sharing, he is transferred to the VC application, in which he confirms the permissions. The problem is that after confirming the user does not return to the application where the sharing was pressed. Instead, the user remains in the VC application and a post of posts is displayed in front of him.

I have added to info.plist

<key>LSApplicationQueriesSchemes</key> <array> <string>vkauthorize</string> </array> <key>CFBundleURLTypes</key> <array> <dict> <key>CFBundleURLSchemes</key> <array> <string>vk0000000</string> </array> <key>CFBundleURLName</key> <string>vk0000000</string> </dict> </array> 

in appDelegate

 func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool { VKSdk.processOpenURL(url, fromApplication: sourceApplication) return true } 

in the controller from where the sharing is caused

 override func viewDidLoad() { super.viewDidLoad() VKSdk.initializeWithDelegate(self, andAppId: "5087664") if VKSdk.wakeUpSession() { } } func vkSdkNeedCaptchaEnter(captchaError: VKError!) { } func vkSdkTokenHasExpired(expiredToken: VKAccessToken!) { } func vkSdkUserDeniedAccess(authorizationError: VKError!) { } func vkSdkShouldPresentViewController(controller: UIViewController!) { } func vkSdkReceivedNewToken(newToken: VKAccessToken!) { } @IBAction func shareToVK(sender: AnyObject) { var imgArray = [AnyObject]() let share = VKShareDialogController() share.text = "Клевое приложение про танки!" let img = VKUploadImage(image:imgToShare, andParams: nil) imgArray.append(img) let link = NSURL(string: "www.ya.ru") share.shareLink = VKShareLink(title: "Preved", link: link) share.uploadImages = imgArray share.completionHandler = { (result : VKShareDialogControllerResult) -> Void in self.dismissViewControllerAnimated(true, completion: nil) } self.presentViewController(share, animated: true, completion: nil) } 

What could be the problem ?

1 answer 1

Sample:

 -(void)viewDidload{ VKSdk *sdkInstance = [VKSdk initializeWithAppId:@"your_vk_id_app"]; [sdkInstance registerDelegate:self]; [sdkInstance setUiDelegate:self]; } -(void)postToVK{ [self dismissViewControllerAnimated:NO completion:nil]; //delay 0,3 sec dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ }); if (![self.presentedViewController isBeingDismissed]) { [self dismissViewControllerAnimated:NO completion:nil]; } VKShareDialogController * shareDialog = [VKShareDialogController new]; //1 shareDialog.text = textBody; //2 shareDialog.requestedScope = [[VKSdk accessToken] permissions]; // передаём права явно //shareDialog.vkImages = @[@"-10889156_348122347",@"7840938_319411365",@"-60479154_333497085"]; shareDialog.shareLink = [[VKShareLink alloc] initWithTitle:[_adsObject adstopic] link:[NSURL URLWithString:[_adsObject adslink]]]; //4 [shareDialog setCompletionHandler: ^(VKShareDialogController *dialog, VKShareDialogControllerResult result) { [self dismissViewControllerAnimated:YES completion:nil]; }]; //5 [self presentViewController:shareDialog animated:YES completion:nil]; //6 } - (NSArray *)activityViewController:(NSArray *)activityViewController itemsForActivityType:(NSString *)activityType { if ([activityType isEqualToString:UIActivityTypeMail]) { return @[emailBody]; } if ([activityType isEqualToString:UIActivityTypeMessage]) { return @[textBody]; } // Automatically copy the text for them [[UIPasteboard generalPasteboard] setString:textBody]; //[self showPopupWithTitle:nil mesage:NSLocalizedString(@"COPYPAST", nil) dismissAfter:1.0]; BOOL isInstalledfb = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"fb://"]]; if (isInstalledfb) { //installed if([activityType isEqualToString:UIActivityTypePostToFacebook] || [activityType isEqualToString:@"com.facebook.Facebook.ShareExtension"] || [activityType.lowercaseString rangeOfString:@"facebook"].length) // Because who knows when they are going to change the activityType string? { //[self dismissViewControllerAnimated:YES completion:nil]; [viewController dismissViewControllerAnimated:YES completion:nil]; [self performSelector:@selector(postToFacebook) withObject:self afterDelay:1]; return nil; } } BOOL isInstalledtw = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"twitter://"]]; if (isInstalledtw) { //installed if([activityType isEqualToString:UIActivityTypePostToTwitter] ) // Because who knows when they are going to change the activityType string? { [self showPopupWithTitle:nil mesage:NSLocalizedString(@"COPYPAST", nil) dismissAfter:1.0]; // [viewController dismissViewControllerAnimated:YES completion:nil]; //[self performSelector:@selector(postToTwitter) withObject:self afterDelay:1]; return nil; } } else { // not instaled } BOOL isInstalledvk = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"vk://"]]; if (isInstalledvk) { //installed SCOPE = @[VK_PER_FRIENDS, VK_PER_WALL, VK_PER_AUDIO, VK_PER_PHOTOS, VK_PER_NOHTTPS, VK_PER_EMAIL, VK_PER_MESSAGES]; [VKSdk wakeUpSession:SCOPE completeBlock:^(VKAuthorizationState state, NSError *error) { // NSLog(@"state vk = %lu",(unsigned long)state); if (state == VKAuthorizationAuthorized) { // Authorized and ready to go // NSLog(@" vk ready auth"); [self performSelector:@selector(postToVK) withObject:self afterDelay:0.2]; } if (state == VKAuthorizationInitialized){ // need Authorized // NSLog(@" vk need auth"); [VKSdk authorize:SCOPE]; } if(error) { // Some error happend, but you may try later NSLog(@"vk some error"); } }]; return nil; } else { // vk app not instaled return @[textBody, myWebsite]; } return nil; } 
  • Please try to write more detailed answers. I am sure the author of the question would appreciate your comments on the topic of the question. - Nicolas Chabanovsky