Objective-C MPMediaItem with null URL - objective-c

I have a project that makes use of a MPMediaPickerController to select audio files from the Media Player. However, when trying to store it's URL, I am getting nothing but null returned. My code can be seen below:
- (void)showMediaPicker:(NSString *)title {
MPMediaPickerController *picker = [[MPMediaPickerController alloc] initWithMediaTypes:MPMediaTypeAny];
picker.delegate = self;
picker.prompt = title;
picker.allowsPickingMultipleItems = NO;
picker.showsCloudItems = NO;
[self.viewController presentViewController:picker animated:YES completion:NULL];
}
- (void)mediaPicker: (MPMediaPickerController *)mediaPicker didPickMediaItems:(MPMediaItemCollection *)mediaItemCollection {
MPMediaItem *item = [mediaItemCollection.items firstObject];
NSURL *assetURL = [item valueForProperty:MPMediaItemPropertyAssetURL];//returning null
NSString *type = [self contentTypeForFile:assetURL.lastPathComponent];
NSString *title = [item valueForProperty:MPMediaItemPropertyTitle];
[self callbackWithName:title type:type url:assetURL];
}
For whatever reason, my *assetURL is nil upon selecting a single audio item from the device's library. The only answers i could find with respect to this problem often relate to the url being null when a cloud item is selected from the MediaPicker. However, as seen above, I have set showCloudItems = NO.
I would greatly appreciate any help; let me know if you need any additional information!

Turns out, music from the "iCloud Music Library" is DRM protected and therefore, the assetURL is left null when selected in the MPMediaPickerController. The simple fix was to turn off the "iCloud Music Library" setting from within the settings for the "Music" app. I would expect picker.showsCloudItems = NO; to prevent this, but apparently I was mistaken.

Related

Apple URL Scheme for launching app from database information

I'm quite frustrated with an issue I'm experiencing that Is coming with a lack of information. I'm unable to locate any information regarding my issue and I'm starting to believe It isn't possible what I want to do. Here is my issue and thank you for reading.
I would like for a button on my ViewController to open Apple Maps from Longitude and Latitude coordinates that are stored in my Sqlite database Tables. I have been able to successfully do this by adding a MapView. I want to reproduce this function and have the user be able to click "Get Directions" button and It will popup the Apple Maps app with the end address setup automatically. By using #"finishLat" and #"finishLng" I'm able to collect the database information. Is this possible when using the Apple URL Scheme?
This is a sample of what the Mapview does with the information. The only part I want from this is the #"finishLat" and #"finishLng". I will also need to use the "Run" feature as well to collect the correct address.
[super viewDidLoad];
CGRect bounds = self.view.bounds;
mapview = [[MapView alloc] initWithFrame:CGRectMake(0, 0, bounds.size.width, bounds.size.height)];
[self.view addSubview:mapview];
NSArray *result = [_runs objectForKey:#"results"];
NSDictionary *arr = [result objectAtIndex:0];
arr = [arr objectForKey:#"run"];
NSMutableArray *arrPlaces = [[NSMutableArray alloc] init];
NSArray *arrDirvers = [arr objectForKey:#"drivers"];
for (int i =0; i < [arrDirvers count]; i++) {
NSDictionary *asdfg = [arrDirvers objectAtIndex:i];
Place *startPt = [[Place alloc] init];
Place *endPt = [[Place alloc] init];
NSString *temp = [asdfg objectForKey:#"startLat"];
startPt.latitude = [temp floatValue];
temp = [asdfg objectForKey:#"startLng"];
startPt.longitude = [temp floatValue];
startPt.name = [asdfg objectForKey:#"name"];
temp = [asdfg objectForKey:#"finishLat"];
endPt.latitude = [temp floatValue];
temp = [asdfg objectForKey:#"finishLng"];
endPt.longitude = [temp floatValue];
endPt.name = [asdfg objectForKey:#"name"];
[arrPlaces addObject:startPt];
[arrPlaces addObject:endPt];
This is what I have.
- (IBAction)GetDirections:(id)sender {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: #"http://maps.apple.com/?q"]];
}
Rather than using openURL: you can create an instance of MKMapItem and use openInMapsWithLaunchOptions:. You can supply the MKLaunchOptionsDirectionsModeKey option to request directions from the users current location.
Alternatively, use openMapsWithItems:launchOptions: to navigate between 2 known locations.
To open in the Apple Maps app use:
- (IBAction)GetDirections:(id)sender
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: #"http://maps.apple.com/?ll=<lattitude>,<longitude>"]];
}
If you want to open Apple Maps to a driving directions screen, you will need to use this url:
http://maps.apple.com/?saddr=<origin>&daddr=<destination>
You can also set one of these to be "Current%20Location" to use the user's current location.

QuickBlox :How to share image/video in peer to peer chat module?

I am trying to share image/video in chat module. I've referred Sample code for this but couldn't find any help.
Alos I've referred http://quickblox.com/modules/chat/ it says Add live chat functions to your app by plugging in our full featured chat module. Fast, Firewall friendly, Robust & Secure. Does it means I have to purchase full featured chat module ?
Please suggest me the right way.
Thanks
Yes, QuickBlox Chat allows to share files, video/audio between 2 users.
Right now iOS SDK doesn't provide methods for send file, live chat. This feature is under Beta testing right now. We are developing easy interface for end users, and we need more time for this. I hope, we will finish it at the end of December.
However, we allow developers develop this feature themself.
What you need for this?
Just create simple TCP/UDP socket between 2 users and send files, audio/video stream through it
For 1 you need to know each other ip address & port - there is STUN protocol that allow to know own address(IP & port) - here is my iOS implementation of STUN protocol https://github.com/soulfly/STUN-iOS
If you already know your address (IP & port) - just send it to your opponent through simple Chat messages - then do 1 item.
Thats all what you need
UPD:
QuickBlox has released VideoChat and Unlimited API Calls for Developers http://quickblox.com/blog/2013/02/quickblox-updates-videochat-and-unlimited-api-calls-for-developers
So, if you want to play with the code and integrate it with your apps, check the Simple Code Sample for iOS http://quickblox.com/developers/SimpleSample-videochat-ios
You have a uploadMethod like this,
-(IBAction)uploadFile:(id)sender
{
self.imagePicker = [[UIImagePickerController alloc] init];
self.imagePicker.allowsEditing = NO;
self.imagePicker.delegate = self;
self.imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:self.imagePicker animated:YES completion:nil];
}
and in the QBChatDelegate, you have this method
- (void)completedWithResult:(Result*)result{
// Upload file result
if(result.success && [result isKindOfClass:[QBCFileUploadTaskResult class]])
{
QBCFileUploadTaskResult *res = (QBCFileUploadTaskResult *)result;
NSUInteger uploadedFileID = res.uploadedBlob.ID;
QBChatMessage *message = [[QBChatMessage alloc] init];
message.recipientID = self.opponent.ID;
NSMutableDictionary *msgDict = [[NSMutableDictionary alloc]init];
[msgDict setValue:[NSNumber numberWithInt:uploadedFileID] forKey:#"fileID"];
message.customParameters = msgDict;
[[QBChat instance] sendMessage:message];
}
else
{
NSLog(#"errors=%#", result.errors);
}
}
Here you are getting the uploaded file id, and you are sending this as a message..
In your chatDidReceiveNotification
- (void)chatDidReceiveMessageNotification:(NSNotification *)notification{
QBChatMessage *message = notification.userInfo[kMessage];
if(message.customParameters != nil)
{
NSUInteger fileID = [message.customParameters[#"fileID"] integerValue];
// download file by ID
[QBContent TDownloadFileWithBlobID:fileID delegate:self];
}
}
This method again calls completedWithResult method, add this code there...
if(result.success && [result isKindOfClass:[QBCFileDownloadTaskResult class]]){
QBCFileDownloadTaskResult *res = (QBCFileDownloadTaskResult *)result;
if ([res file]) {
UIImageView* imageView = [[UIImageView alloc] initWithImage:[UIImage imageWithData:[res file]]];
[self.messages addObject:imageView];
[self.messagesTableView reloadData];
}
}else{
NSLog(#"errors=%#", result.errors);
}
If you want to display the image in your tableView, change your cellForRow like this..
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if([[self.messages objectAtIndex:indexPath.row]isKindOfClass:[QBChatMessage class]])
{
static NSString *ChatMessageCellIdentifier = #"ChatMessageCellIdentifier";
ChatMessageTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ChatMessageCellIdentifier];
if(cell == nil){
cell = [[ChatMessageTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ChatMessageCellIdentifier];
}
QBChatMessage *message = (QBChatMessage *)self.messages[indexPath.row];
//
[cell configureCellWithMessage:message is1To1Chat:self.opponent != nil];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
else if ([[self.messages objectAtIndex:indexPath.row]isKindOfClass:[UIImageView class]])
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"CellIdentifier"];
if (nil == cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:#"CellIdentifier"];
}
UIImageView *receivedImage = [self.messages objectAtIndex:indexPath.row];
[cell.contentView addSubview:receivedImage];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
}
I have tried this and this piece of code works.
Cheers.
If your requirement is only for 1-1 chat, then please check this link
http://quickblox.com/developers/SimpleSample-chat_users-ios#Send_files
This will work for 1-1 chat.
But, in case of room I am unable to find any solution as of now. I am trying to figure out. If anybody knows a way, please post here.

iOs Custom scheme in MFMailComposeViewController

I'm trying to send via MFMailComposeViewController a custom url scheme so that the receipient could tap on the embedded link and open my application on his iphone.
So far the receipient gets an email but nothing happens when he taps on the LINK.
here is the code:
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self; // <- very important step if you want feedbacks on what the user did with your email sheet
[picker setSubject:#"Incoming task"];
// Fill out the email body text
NSString * types = #"";
for(NSString *type in task.location_types){
types = [types stringByAppendingFormat:#"%#|",type];
}
if(types.length > 1){
types = [types substringToIndex:types.length - 1];
}
NSString *desc = [task.description stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *link = [NSString stringWithFormat:#"helpy://?taskid=%d&desc=%#&types=%#\"",task.TaskId,desc,types];
NSString *emailBody = [NSString stringWithFormat:#"TAP HERE<script type=\"text/javascript\" charset=\"utf-8\">function doSomething() { window.location = \"%#\;return false;}</script>",link];
[picker setMessageBody:emailBody isHTML:YES];
picker.navigationBar.barStyle = UIBarStyleBlack;
[controller presentModalViewController:picker animated:YES];
[picker release];
helpy://?taskid=..... is my custom registered URL Scheme and if I type it from the address bar of the browser it opens up my application on the iPhone.
For some reason when this link is embedded into email, tapping it does not do anything.
Any help?
thanks
I highly doubt that Mail will execute JavaScript on iOS (even on the desktop I highly doubt it, but haven't tried it though). Simply set the URL as the href attribute of your hyperlink and everything should work fine. Any reason why you want to do it with JavaScript? I'm just curious ;-)
NSString *link = [NSString stringWithFormat:#"helpy://?taskid=%d&desc=%#&types=%#\"",task.TaskId,desc,types];
NSString *emailBody = [NSString stringWithFormat:#"TAP HERE", link];

ShareKit email form not always displaying

I'm using ShareKit to share objects to Twitter, Facebook, and Email. Twitter and Facebook works fine, but email doesn't. And I don't really know why.
It seems like it works quite randomly.
I set it up like this:
[self.customView.shareButton addTarget:self action:#selector(sharePost:) forControlEvents:UIControlEventTouchUpInside];
- (void)sharePost:(UIButton *)sender
{
NSURL *url = [NSURL URLWithString:self.currentPost.link];
// Add image.
NSString *imageUrlString = [NSString stringWithFormat:[link]];
NSURL *imageUrl = [NSURL URLWithString:imageUrlString];
UIImageView *postImage = [[UIImageView alloc] init];
[postImage setImageWithURL:imageUrl];
SHKItem *item = [SHKItem image:postImage.image title:[NSString stringWithFormat:#"%#", self.currentPost.title]];
[item setURL:url];
[item setMailBody:[NSString stringWithFormat:#"%# %#", self.currentPost.title, self.currentPost.link]];
// Get the ShareKit action sheet
// This works
SHKActionSheet *actionSheet = [SHKActionSheet actionSheetForItem:item];
// ShareKit detects top view controller (the one intended to present ShareKit UI) automatically,
// but sometimes it may not find one. To be safe, set it explicitly.
[SHK setRootViewController:self];
// Display the action sheet.
[actionSheet showInView:self.view];
}
Any ideas or what I'm missing or doing wrong?
Try to change the RootViewController and view you are using:
[SHK setRootViewController:self.view.window.rootViewController];
[actionSheet showInView:self.view.window.rootViewController.view];
Most likely your view controller hierarchy is somewhat messed up.

Sharekit not populating facebook text box

Here is the code I use. I am able to see popup but I do not see the text pre-populated in the facebook popup.
Any suggestions?
- (IBAction) shareViaFacebook
{
[self prepareToShare];
// create the item to share
NSString *share = [NSString stringWithFormat:#"I'm tracking %# in some stuff, check it out! http://somewebsite.com/g/%d #TEST",
self.game.name,
[self.game.serverId intValue]];
SHKItem *item = [SHKItem text:share];
// share the item
[SHKFacebook shareItem:item];
}
On the same age, the following code for twitter works just fine. That is everything gets prepopulated
- (IBAction) shareViaTwitter
{
[self prepareToShare];
// create the item to share
NSString *share = [NSString stringWithFormat:#"I'm tracking %# in some stuff, check it out! http://somewebsite.com/g/%d #TEST",
self.game.name,
[self.game.serverId intValue]];
SHKItem *item = [SHKItem text:share];
// share the item
[SHKTwitter shareItem:item];
}
This is an example from my project using ShareKit:
NSString *finalPostedString = [[NSString alloc] initWithFormat:#"Check out this"];
SHKItem *item1= [SHKItem text:finalPostedString];
SHKActionSheet *actionSheet = [SHKActionSheet actionSheetForItem:item1];
[actionSheet showInView:self];
Try that out and hopefully it helps.
EDIT: Or more specifically, check this thread out that also should answer your question:
iPhone/iOS - How to use "ShareKit" to post only to Facebook or only to Twitter