Uploading photos to Instagram via your own iOS app

后端 未结 8 1438
执笔经年
执笔经年 2020-12-23 09:57

Instagram recently made a change to their API policy which allowed developers to post pictures to the Instagram platform via their own app. Several other techniques we\'re p

8条回答
  •  庸人自扰
    2020-12-23 10:57

    You can simply use UIActivityViewController as well,

    if([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"instagram://app"]]) //check for App is install or not
        {
            NSArray * activityItems = [NSArray arrayWithObjects:newImage, nil];
            UIActivityViewController * activityController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
            activityController.excludedActivityTypes = [NSArray arrayWithObjects:UIActivityTypePostToWeibo, UIActivityTypePrint, UIActivityTypeCopyToPasteboard, UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll, nil];
            
            [self presentViewController:activityController animated:YES completion:nil];
            
            //after sent
            [activityController setCompletionWithItemsHandler:^(NSString *act, BOOL done, NSArray *returnedItems, NSError *activityError){
                
                if (done){
                    
                    UIAlertController *alert;
                    UIAlertAction* ok = [UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action){
                        [alert dismissViewControllerAnimated:YES completion:nil];
                    }];
                    
                    alert = [UIAlertController alertControllerWithTitle:@"Successfully Posted!" preferredStyle:UIAlertControllerStyleAlert];
                    [alert addAction: ok];
                    [self presentViewController:alert animated:YES completion:nil];
                    
                    [self dismissViewControllerAnimated:YES completion:nil];
                }
            }];
    }
    

提交回复
热议问题