Instagram iPhone Hook Description - objective-c

Is there a opportunity to add a description to a new Instagram post created via iPhone Hook?
NSString *moviePath = outputPath;
NSString *caption = #"description";
NSURL *movieURL = [NSURL fileURLWithPath:moviePath isDirectory:NO];
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library writeVideoAtPathToSavedPhotosAlbum:movieURL
completionBlock:^(NSURL *assetURL, NSError *error)
{
NSURL *instagramURL = [NSURL URLWithString:
[NSString stringWithFormat:#"instagram://library?AssetPath=%#&annotation=%#",
[[assetURL absoluteString] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet alphanumericCharacterSet]],
[caption stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet alphanumericCharacterSet]]]
];
if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {
[[UIApplication sharedApplication] openURL:instagramURL];
}
else {
NSLog(#"Can't open Instagram");
}
}];
I tried thus but it doesn't show anything in the description text field. Can you help me?

Related

Pause/Resume download with AFNetworking 3.0 and NSURLSessionDownloadTask Objective-C, OSX

I have trouble with creating Pause/Resume download methods in my Objective-C osx app, I have tried some of the answers I found here but nothing seems to work.
Here is my code: `-(void)pauseDownload:(id)sender {
if(!downloadTask) return;
[downloadTask cancelByProducingResumeData:^(NSData * _Nullable resumeData) {
if (!resumeData) return;
[self setDownloadResumeData:resumeData];
[self setDownloadTask:nil];
}];
NSString *datastring = [[NSString alloc] initWithData:downloadResumeData encoding:NSUTF8StringEncoding];
isDownloading = NO;
NSLog(#"data %#", datastring);}`
Continue method:
-(void)continueDownload:(id)sender {
if (!self.downloadResumeData) {
return;
}
self.downloadTask = [manager.session downloadTaskWithResumeData:self.downloadResumeData];
[self.downloadTask resume];
[self setDownloadResumeData:nil];}
And download request with download task:
-(void)downloadRequest:(NSString *)url toDirectory:(NSString *)directoryName atIndex:(NSInteger) rowIndex {
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];
NSURL *URL = [NSURL URLWithString:url];
NSURLRequest *request = [NSURLRequest requestWithURL:URL];
NSString *downloadDirectoryPath = [[NSUserDefaults standardUserDefaults] objectForKey:#"downloadPath"];
NSURL *downloadURL;
if (directoryName != nil || ![directoryName isEqualToString:#""]) {
downloadURL = [self createDownloadDirectoryIn:downloadDirectoryPath withName:directoryName];
} else {
downloadURL = [NSURL URLWithString:[[NSUserDefaults standardUserDefaults] objectForKey:#"downloadFolderPath"]];
}
downloadTask = [manager downloadTaskWithRequest:request progress:^(NSProgress * _Nonnull downloadProgress) {
NSLog(#"%#", downloadProgress);
// [self downloadStartedWithDownloadId:downloadID andDeviceId:userDeviceID];
isDownloading = YES;
NSNumber *downloadPercentage = [NSNumber numberWithInteger:downloadProgress.fractionCompleted *100];
progressArray[rowIndex] = downloadPercentage;
[self updateProgressBars];
} destination:^NSURL *(NSURL *targetPath, NSURLResponse *response) {
return [downloadURL URLByAppendingPathComponent:[response suggestedFilename]];
} completionHandler:^(NSURLResponse *response, NSURL *filePath, NSError *error) {
[[files objectAtIndex:self.tableOfContents.selectedRow] setIsFinishedDownloading:YES];
// [self downloadFinishedWithDownloadID:downloadID andDeviceID:userDeviceID];
NSLog(#"File downloaded to: %#", filePath);
}] ;
[downloadTask resume];}
Appreciate any help.

UserNotification ios 10

I want to show a gif animation in UserNotification(local notification), but i am only able to show an image in user notification, the animation don't get displayed. I am doing this in objective-c
my code
//scheduling an notification
NSString *UNExtensionID=#"animatedContentExtension";
NSError *error;
UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init];
content.title = [NSString localizedUserNotificationStringForKey:#"Test Notification:" arguments:nil];
content.body = [NSString localizedUserNotificationStringForKey:#"Hello thereļ¼It is a multimedia notification with animation!"
arguments:nil];
content.sound = [UNNotificationSound defaultSound];
UNNotificationAttachment *attachment;
NSURL *url = [[NSBundle mainBundle] URLForResource:#"bike" withExtension:#"png"];
attachment=[UNNotificationAttachment attachmentWithIdentifier:#"imageID"
URL: url
options:nil
error:&error];
content.attachments=#[attachment];
content.categoryIdentifier=UNExtensionID;
content.badge = #([[UIApplication sharedApplication] applicationIconBadgeNumber] + 1);
UNTimeIntervalNotificationTrigger *trigger = [UNTimeIntervalNotificationTrigger
triggerWithTimeInterval:20.0f repeats:NO];
UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:#"FiveSecond"
content:content trigger:trigger];
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
[center addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) {
if (!error) {
NSLog(#"add NotificationRequest succeeded!");
}
}];
// this code in AppDelegate
- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request
withContentHandler:(void (^)(UNNotificationContent *contentToDeliver))contentHandler{
UNNotificationAttachment *attachment;
NSError *error;
UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init];
NSURL *url = [[NSBundle mainBundle] URLForResource:#"bike" withExtension:#"png"];
attachment=[UNNotificationAttachment attachmentWithIdentifier:#"imageID"
URL:url
options:nil
error:&error];
content=request.content.mutableCopy;
content.attachments= #[attachment];
`enter code here`contentHandler(content);
}
You have to add your .gif file in the Notification Service Extension file.
You can create an UNNotificationAttachment object out of it and pass in the completionHandler of func didReceiveNotificationRequest(request: UNNotificationRequest, withContentHandler contentHandler: (UNNotificationContent) -> Void) method of UNNotificationServiceExtension subclass.

How do I play a video from Cloudkit on tvOS?

I have a problem i have been trying to solve for a day and i tired of beating my head aaginst the wall. Anyone know how to do this?
Number 1 Works Great
Works Great
- (void) viewDidLoad {
[super viewDidLoad];
NSURL *url = [NSURL URLWithString:#"http://techslides.com/demos/sample-videos/small.mp4"];
AVPlayer *avPlayer = [[AVPlayer alloc] initWithURL:url];
self.player = avPlayer;
[self.player play];
}
Does not work
- (void) viewDidLoad {
[super viewDidLoad];
CKAsset *asset = record[#"VideoFile"];
AVPlayer *avPlayer = [[AVPlayer alloc] initWithURL:asset.fileURL];
self.player = avPlayer;
[self.player play];
}
Does not work
- (void) viewDidLoad {
[super viewDidLoad];
CKAsset *asset = record[#"VideoFile"];
NSString *fileName = record[#"videoFileKey"];
NSData *data = [NSData dataWithContentsOfURL:asset.fileURL];
NSString *cachesDirectoryPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *path = [cachesDirectoryPath stringByAppendingPathComponent:[NSString stringWithFormat:#"%#.mp4", fileName]];
[data writeToFile:path atomically:YES];
if ([[NSFileManager defaultManager] fileExistsAtPath:path]) {
NSURL *url = [NSURL URLWithString:path];
AVPlayer *avPlayer = [[AVPlayer alloc] initWithURL:url];
self.player = avPlayer;
[self.player play];
}
}

FBFriendPickerViewController to save friends pictures

Is it possible to get friends userpics using FBFriendPickerViewController?
I tried:
FBFriendPickerViewController *friendPicker = [[FBFriendPickerViewController alloc] init];
friendPicker.fieldsForRequest = [[NSSet alloc] initWithObjects:#"picture", nil];
[friendPicker loadData];
[friendPicker presentModallyFromViewController:self
animated:YES
handler:^(FBViewController *sender, BOOL donePressed) {
if (donePressed) {
UIImage *pic = friend[#"picture"];
...
But there is nil in friend[#"picture"].
Try this code inside your block, here i got it working.
if (donePressed) {
for (id<FBGraphUser> user in self.friendPickerController.selection) {
UIImage *pic = user[#"picture"];
NSLog(#"%#",pic);
}
}
Solution
NSURL *profilePictureURL = [NSURL URLWithString:friend[#"picture"][#"data"][#"url"]];
NSURLRequest *profilePictureURLRequest = [NSURLRequest requestWithURL:profilePictureURL cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10.0f]; //
[NSURLConnection sendAsynchronousRequest:profilePictureURLRequest
queue:[NSOperationQueue mainQueue]
completionHandler:^(NSURLResponse* response, NSData* receivedData, NSError* error)
{
UIimage *userpic = [UIImage imageWithData:receivedData];
}];

iOS 4.3 crashes when uploading video

I have an iPhone app that uploads images and video to a web service using ASIHTTPRequest. Everything works great on devices running iOS 5, but crashes on 4.3 and below devices after returning from the UIImagePickerController. The video is compressed bu=y the picker, then the app crashes. Below is the code from the -(void)imagePickerController: didFinishPickingMediaWithInfo: method, and also from the method that post the video to the server and a method that captures an image from the video to use as a thumbnail. Any ideas on what's causing the crashes in 4.3?
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
self.mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if ([self.mediaType isEqualToString:(NSString *)kUTTypeMovie])
{
NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
// Get asset to use for orientation determination
AVAsset *myAsset = [AVAsset assetWithURL:videoURL];
self.videoOrientation = [self UIInterfaceOrientationToString:[self orientationForTrack:myAsset]];
UIImage *videoThumbnail = [self getVideoThumbnailFromAVAsset:myAsset];
self.photoImageView.image = videoThumbnail;
self.videoData = [[NSMutableData alloc]initWithContentsOfURL:videoURL];
}
[self dismissModalViewControllerAnimated:YES];
}
-(UIImage*)getVideoThumbnailFromAVAsset:(AVAsset *)myAsset {
AVAssetImageGenerator *imageGenerator = [[AVAssetImageGenerator alloc] initWithAsset:myAsset];
Float64 durationSeconds = CMTimeGetSeconds([myAsset duration]);
CMTime midpoint = CMTimeMakeWithSeconds(durationSeconds/2.0, 600);
NSError *error = nil;
CMTime actualTime;
UIImage *myImage;
CGImageRef halfWayImage = [imageGenerator copyCGImageAtTime:midpoint actualTime:&actualTime error:&error];
if (halfWayImage != NULL) {
myImage = [UIImage imageWithCGImage:halfWayImage];
CGImageRelease(halfWayImage);
}
return myImage;
}
- (void)postMessage:(id)sender {
self.uploadButton.enabled = NO;
[self.descriptionTextField resignFirstResponder];
[self.titleTextField resignFirstResponder];
NSUserDefaults *settings = [NSUserDefaults standardUserDefaults];
NSString *sessionKey = [settings stringForKey: #"sessionKey"];
// build URL for request
NSString *baseURL;
NSString *endPoint;
// code here that creates the url component strings baseURL and endPoint
NSString *fullURL = [NSString stringWithFormat:#"%#%#", baseURL, endPoint];
NSURL *url = [NSURL URLWithString:fullURL];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
request.postFormat = ASIMultipartFormDataPostFormat;
NSString *teamIDStr = [NSString stringWithFormat:#"%d",[self.teamID intValue]];
[request setPostValue:sessionKey forKey:#"sessionKey"];
[request setPostValue:teamIDStr forKey:#"TeamID"];
[request setPostValue:titleTextField.text forKey:#"lessonName"];
[request setPostValue:descriptionTextField.text forKey:#"lessonDesc"];
[request setPostValue:self.videoOrientation forKey:#"videoOrientation"];
//create video file name
NSDate *date1=[NSDate date];
NSDateFormatter *formatter1 = [[NSDateFormatter alloc] init];
[formatter1 setDateFormat:#"hhmm"];
NSString *valuestr = [formatter1 stringFromDate:date1];
NSString *moviename = [NSString stringWithFormat:#"video_%#.mov", valuestr];
[request setData:self.videoData withFileName:moviename andContentType:#"video/quicktime" forKey:#"file1.mov"];
[request setUploadProgressDelegate:self.progressBar];
[request setShowAccurateProgress:YES];
self.progressBar.hidden = NO;
[request setDelegate:self];
[request setTimeOutSeconds:600];
[request startAsynchronous];
}
SImple answer to this issue: The AVAsset class method
+ (id)assetWithURL:(NSURL *)URL
is not available before iOS 5.0. You must use the concrete subclass AVURLAsset to instantiate an AVAsset for iOS 4.0 and 4.3, using its class method
+ (AVURLAsset *)URLAssetWithURL:(NSURL *)URL options:(NSDictionary *)options