Error in PDKPin.m for Pinterest iOS SDK - ios

I am currently using the iOS SDK's "getAuthenticatedUserPinsWithFields" method to return a user's pins:
let fields = ["id","note","url","image"] as NSSet
PDKClient.sharedInstance().getAuthenticatedUserPinsWithFields(fields as Set<NSObject>,
success: { (responseObject :PDKResponseObject!) -> Void in
I believe I traced the error to PDKPin.m initWithDictionary:
(instancetype)initWithDictionary:(NSDictionary *)dictionary
{
self = [super initWithDictionary:dictionary];
if (self) {
// _url = [NSURL URLWithString:dictionary[#"link"]];
_url = [NSURL URLWithString:dictionary[#"url"]];
_descriptionText = dictionary[#"note"];
_board = [PDKBoard boardFromDictionary:dictionary[#"board"]];
_creator = [PDKUser userFromDictionary:dictionary[#"creator"]];
_metaData = dictionary[#"metadata"];
_repins = [self.counts[#"repins"] unsignedIntegerValue];
_likes = [self.counts[#"likes"] unsignedIntegerValue];
_comments = [self.counts[#"comments"] unsignedIntegerValue];
}
return self;
}
The #"link" reference always returns nil but using "url" will return the url to the pin. Is the SDK wrong in this case?
Thanks, Anita

Related

How to Implement and using nextTokenPage using Using GTLRYoutube iOS Objective C

so I have a question how to use & implement nextPageToken Using GTLRYoutube in iOS Objective c which the example result is here :
( https://developers.google.com/youtube/v3/docs/playlistItems/list ) and set the maxResults to "10" and the "nextPageToken will generate it".
btw my flow to get the :
ChannelID
and getting PlaylistID -> to get PlaylistItems
and VideoID one by one
and the code like this :
1.
- (void)fetchChannelResource {
GTLRYouTubeQuery_ChannelsList *query =
[GTLRYouTubeQuery_ChannelsList queryWithPart:#"snippet,contentDetails"];
query.mine = true;
[self.service executeQuery:query
delegate:self
didFinishSelector:#selector(displayResultWithTicket:finishedWithObject:error:)];
}
and execute query :
- (void)displayResultWithTicket:(GTLRServiceTicket *)ticket
finishedWithObject:(GTLRYouTube_ChannelListResponse *)channels
error:(NSError *)error {
if (error == nil) {
NSMutableString *output = [[NSMutableString alloc] init];
if (channels.items.count > 0) {
self.youtubeChannelDataArray = channels.items;
[output appendString:#"Channel information:\n"];
for (GTLRYouTube_Channel *channel in channels) {
NSString *title = channel.snippet.title;
NSString *description = channel.snippet.description;
NSNumber *viewCount = channel.statistics.viewCount;
[output appendFormat:#"Title: %#\nDescription: %#\nViewCount: %#\n", title, description, viewCount];
NSString *uploadID = channel.contentDetails.relatedPlaylists.uploads;
self.youtubeUploadID = uploadID;
}
//CALL fetchPlaylistItemResource
[self fetchPlaylistItemResource];
} else {
[output appendString:#"Channel not found."];
}
// self.output.text = output;
} else {
// [self showAlert:#"Error" message:error.localizedDescription];
}
}
all the data saved in NSArray and NSMutableDictionary.
and in other viewController, i need to display them all.. but the problem is how to implement with nextPageToken which is will display 5 items resultPerPage ??
because when I use this "GTLRYoutube", looks like we don't need to make a new model, just use the model from GTLRYoutube, besides that also didn't make mapping and access the youtube API in the Datamanager.m
anyone have a suggestion or advise ???
thanks before!

trouble with iOS9 search API NSUserActivity

When I watch videos about iOS9 search API WWDC2015,there is a demo like this:
var activity:NSUserActivity = NSUserActivity(activityType:"com.yummly.browseRecipe")
activity.title = "Baked Potato Chips"
activity.userInfo = ["id":"http://www.yummly.com/recipe/BPC-983195"]
activity.eligibleForSearch = true
activity.becomeCurrent()
I copy this code to my Xcode and run it, when I search by Spotlight, there is no results. What's wrong with it? Bug for iOS9?
For some reason, you must keep a reference to your NSUserActivity object after you call activity.becomeCurrent(). Like this (Swift):
activity.becomeCurrent()
self.lastActivity = activity
where "lastActivity" is a property of the class you are in.
I did like this, is in objective-C, but you can easily translate to swift
if ([CSSearchableItemAttributeSet class]) {
CSSearchableItemAttributeSet* attributes = [[CSSearchableItemAttributeSet alloc]initWithItemContentType:#"kUTTypePackage"];//Set you content type
attributes.title = model.name;
attributes.contentDescription = model.description;
attributes.identifier = model.fileURL.lastPathComponent;
UIImage* backImage = [UIImage imageWithData:model.imageData];
if (backImage == nil) {
attributes.thumbnailData = UIImageJPEGRepresentation([UIImage imageNamed:#"DefaultImage"], 0.5);
}else{
attributes.thumbnailData = model.imageData;
}
NSString* domainID = #"com.myapp.mycompany";
NSString* uniqueID = model.fileURL.lastPathComponent;
CSSearchableItem* item = [[CSSearchableItem alloc]initWithUniqueIdentifier:uniqueID //value passed from NSUserActivity inside .userInfo
domainIdentifier:domainID
attributeSet:attributes];
NSLog(#"Item Attributes:%#",item.attributeSet.identifier);
CSSearchableIndex* index = [CSSearchableIndex defaultSearchableIndex];
[index indexSearchableItems:#[item] completionHandler:^(NSError * _Nullable error) {
if (!error) {
NSLog(#"Item \"%#\" indexed",model.name);
}else{
NSLog(#"Error, \"%#\" not indexed: %#, %#",model.name,error, error.userInfo);
}
}];
}else{
NSLog(#"iOS < 9");
}
You need to attach the NSUserActivity to the controller like below.
controller.userActivity = activity

Downloading calendar data in Objective-C

I am trying to download google calendar data.
I am following a tutorial this link according to which implementing some of the GoogleOAuth delegate methods will let me get my desired data.
First I converted the response JSON data into an NSDictionary object and after that, I, NSLog this dictionary, to see the way the returned data is formed which is as shown below.
calendarInfoDict is {
etag = "\"1436255371893000\"";
items = (
{
accessRole = owner;
backgroundColor = "#9a9cff";
colorId = 17;
defaultReminders = (
{
method = popup;
minutes = 30;
}
);
etag = "\"1436255371893000\"";
foregroundColor = "#000000";
id = "sabiranthapa#gmail.com";
kind = "calendar#calendarListEntry";
notificationSettings = {
notifications = (
{
method = email;
type = eventCreation;
},
{
method = email;
type = eventChange;
},
{
method = email;
type = eventCancellation;
},
{
method = email;
type = eventResponse;
}
);
};
primary = 1;
selected = 1;
summary = "sabiranthapa#gmail.com";
timeZone = "Asia/Calcutta";
},
{
accessRole = reader;
backgroundColor = "#92e1c0";
colorId = 13;
defaultReminders = (
);
description = "Displays birthdays of people in Google Contacts and optionally \"Your Circles\" from Google+. Also displays anniversary and other event dates from Google Contacts, if applicable.";
etag = "\"1436255358367000\"";
foregroundColor = "#000000";
id = "#contacts#group.v.calendar.google.com";
kind = "calendar#calendarListEntry";
summary = Birthdays;
timeZone = "Asia/Calcutta";
}
);
kind = "calendar#calendarList";
nextSyncToken = 00001436255371893000;
}
According to tutorial there is a block containing a bunch of information regarding every calendar I have created in Google Calendars inside curly bracket. But I am not getting any events that I have saved which can be seen in Google Calendar after signing in gmail but not in my apps where I need to work with it.
My code is
-(void)responseFromServiceWasReceived:(NSString *)responseJSONAsString andResponseJSONAsData:(NSData *)responseJSONAsData{
NSError *error;
if ([responseJSONAsString rangeOfString:#"calendarList"].location != NSNotFound) {
NSDictionary *calendarInfoDict = [NSJSONSerialization JSONObjectWithData:responseJSONAsData options:NSJSONReadingMutableContainers error:&error];
NSLog(#"calendarInfoDict is %#", calendarInfoDict);
if (error) {
NSLog(#"%#", [error localizedDescription]);
}
else{
NSArray *calendarsInfo = [calendarInfoDict objectForKey:#"items"];
if (_arrGoogleCalendars == nil) {
_arrGoogleCalendars = [[NSMutableArray alloc] init];
}
for (int i=0; i<[calendarsInfo count]; i++) {
NSDictionary *currentCalDict = [calendarsInfo objectAtIndex:i];
NSArray *values = [NSArray arrayWithObjects:[currentCalDict objectForKey:#"id"],
[currentCalDict objectForKey:#"summary"],
nil]; NSArray *keys = [NSArray arrayWithObjects:#"id", #"summary", nil];
[_arrGoogleCalendars addObject:
[[NSMutableDictionary alloc] initWithObjects:values forKeys:keys]];
}
_dictCurrentCalendar = [[NSDictionary alloc] initWithDictionary:[_arrGoogleCalendars objectAtIndex:0]];
[_barItemPost setEnabled:YES];
[_barItemRevokeAccess setEnabled:YES];
[self showOrHideActivityIndicatorView];
But I always end up with condition
if (_arrGoogleCalendars == nil) {
_arrGoogleCalendars = [[NSMutableArray alloc] init];
}
without able to access my events.
How can I download (or access) my Events from google calendar?

Convert Swift method using extend and append functions to Objective-C

I have this Swift method that I want to convert to Objective-C. The method is using the extend method of Array and as far as I understand it just adds an object to the array while calling itself again.
Swift:
///the method to serialized all the objects
func serializeObject(object: AnyObject,key: String?) -> Array<HTTPPair> {
var collect = Array<HTTPPair>()
if let array = object as? Array<AnyObject> {
for nestedValue : AnyObject in array {
collect.extend(self.serializeObject(nestedValue,key: "\(key!)[]"))
}
} else if let dict = object as? Dictionary<String,AnyObject> {
for (nestedKey, nestedObject: AnyObject) in dict {
var newKey = key != nil ? "\(key!)[\(nestedKey)]" : nestedKey
collect.extend(self.serializeObject(nestedObject,key: newKey))
}
} else {
collect.append(HTTPPair(value: object, key: key))
}
return collect
}
What I've done so far in Objective-C.
- (NSArray*) serializeObject:(id)obj key:(NSString*)key
{
NSMutableArray* collect = [NSMutableArray array];
if ([obj isKindOfClass:[NSArray class]])
{
NSArray* objArray = obj;
if (obj)
{
for (id nestedObj in objArray)
{
[collect addObject:[self serializeObject:nestedObj key:[NSString stringWithFormat:#"%#[]", key]]];
}
}
}
else if ([obj isKindOfClass:[NSDictionary class]])
{
NSDictionary* dict = obj;
if (dict)
{
for (NSString* nestedKey in dict)
{
NSString* newKey = key != nil ? [NSString stringWithFormat:#"%#[%#]", key, nestedKey] : nestedKey;
id nestedObject = [dict objectForKey:newKey];
if (nestedObject)
{
[collect addObject:[self serializeObject:nestedObject key:newKey]];
}
}
}
}
else
{
[collect addObject:[[WEEHTTPPair alloc] initWithValue:obj andKey:key]];
}
return collect;
}
The goal is to get an NSArray of WEEHTTPPair objects for every key/value pair in the dictionary but I lose the meaning of extend and append to apply in my Objective-C code. For me it looks like both are adding the object to the array which is created new anyway but it's more that I lack in knowledge so far.
[EDIT]
The method is used accordingly.
Swift.
///convert the parameter dict to its HTTP string representation
func stringFromParameters(parameters: Dictionary<String,AnyObject>) -> String {
return join("&", map(serializeObject(parameters, key: nil), {(pair) in
return pair.stringValue()
}))
}
I converted to Objective-C borrowed BlockKits map extension.
Objective-C.
- (NSString*) stringFromParameters:(NSDictionary*)parameters
{
WEENSArrayBlocksKit* blockKit = [WEENSArrayBlocksKit new];
NSArray* serializedParams = [self serializeObject:parameters key:nil];
NSArray* arrayParams = [blockKit bk_map:serializedParams withBlock:^id(id obj)
{
// obj is an array without the desired results
WEEHTTPPair* httpPair = obj;
NSString* stringValue = nil;
if (httpPair)
{
stringValue = [httpPair stringValue];
}
return stringValue;
}];
NSString* joinedString = [arrayParams componentsJoinedByString:#"&"];
return joinedString;
}
When you do this:
[collect addObject:[self serializeObject:nestedObject key:newKey]];
You are adding an NSArray to your collect object. Instead, you want to add the objects contained within the response to collect:
[collect addObjectsFromArray:[self serializeObject:nestedObject key:newKey]];

Parse YouTube JSON for UITableView

I am trying to have a UITableView that displays the title, thumbnail, viewcount, and duration of some youtube videos on a specific channel. The link is this
https://gdata.youtube.com/feeds/api/videos?q=remedyLIVE&max-results=5&v=2&alt=jsonc&orderby=published
And the JSON looks like this
{
apiVersion = "2.1";
data = {
items = (
{
accessControl = {
autoPlay = allowed;
comment = allowed;
commentVote = allowed;
embed = allowed;
list = allowed;
rate = allowed;
syndicate = allowed;
videoRespond = moderated;
};
aspectRatio = widescreen;
category = Music;
commentCount = 0;
content = {
1 = "rtsp://r3---sn-jc47eu7l.c.youtube.com/CiILENy73wIaGQkbMrdTdbNpexMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp";
5 = "https://www.youtube.com/v/e2mzdVO3Mhs?version=3&f=videos&app=youtube_gdata";
6 = "rtsp://r3---sn-jc47eu7l.c.youtube.com/CiILENy73wIaGQkbMrdTdbNpexMYESARFEgGUgZ2aWRlb3MM/0/0/0/video.3gp";
};
description = "In this episode of IchthusTV My Epic talks about seeking help within the church. -- Text 'Remedy' to 313131 if you need to chat. RemedyLIVE: We Chat, Listen, and Love www.remedyLIVE.com.";
duration = 109;
id = e2mzdVO3Mhs;
player = {
default = "https://www.youtube.com/watch?v=e2mzdVO3Mhs&feature=youtube_gdata_player";
mobile = "https://m.youtube.com/details?v=e2mzdVO3Mhs";
};
thumbnail = {
hqDefault = "https://i.ytimg.com/vi/e2mzdVO3Mhs/hqdefault.jpg";
sqDefault = "https://i.ytimg.com/vi/e2mzdVO3Mhs/default.jpg";
};
title = "My Epic - Help within the Church";
updated = "2014-11-11T20:00:03.000Z";
uploaded = "2014-11-11T20:00:03.000Z";
uploader = chatlistenlove;
},
{
accessControl = {
autoPlay = allowed;
comment = allowed;
commentVote = allowed;
embed = allowed;
list = allowed;
rate = allowed;
syndicate = allowed;
videoRespond = moderated;
};
aspectRatio = widescreen;
category = People;
commentCount = 0;
content = {
etc... I won't post the whole thing but you can see it on the link above! As this is my first time working with JSON I understand that I need to parse this to an array or dictionary but I am just a bit confused on what exactly the "objectforkey" methods look like once I have the data. None of the tutorials I see apply to what I am doing so specific help would be awesome! Here is my code so far
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
[self.tableView registerNib:[UINib nibWithNibName:#"RemedyYouTubeTableViewCell"
bundle:[NSBundle mainBundle]]
forCellReuseIdentifier:#"RemedyYouTubeTableViewCell"];
NSURL *youtubeURL = [NSURL URLWithString:#"https://gdata.youtube.com/feeds/api/videos?q=remedyLIVE&max-results=5&v=2&alt=jsonc&orderby=published"];
NSData *data = [NSData dataWithContentsOfURL:youtubeURL];
if (data == nil)
{
NSLog(#"data is nil");
}
else
{
NSError *error;
titleArray = [[NSMutableArray alloc]init];
videoIDArray = [[NSMutableArray alloc]init];
thumbArray = [[NSMutableArray alloc]init];
NSArray *json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
NSLog(#"%#", json);
for (NSDictionary *item in json)
{
NSDictionary* snippet = [item objectForKey:#"snippet"];
title = [snippet objectForKey:#"title"];
videoID = [[snippet objectForKey:#"resourceId"] objectForKey:#"videoId"];
thumbURL = [[[snippet objectForKey:#"thumbnails"] objectForKey:#"default"] objectForKey:#"url"];
[titleArray addObject:title];
[videoIDArray addObject:videoID];
[thumbArray addObject:thumbURL];
}
[self.tableView reloadData];
}
For example why is the word "snippet" chosen? I found this on another stack overflow post about this but I don't understand. Thanks in advance!
As mentioned in the comments, you can parse NSDictionary objects (translated by parsing JSON objects) using short hand notation. To get to the value you want, use something like this:
NSURL* playbackUrl = [NSURL urlWithString:yourDictionary[#"data"][#"items"][#"player"]["mobile"]];
To prevent crashes when the property doesn't exist, you'll want to use a try catch block:
#try {
NSURL* playbackUrl = [NSURL urlWithString:yourDictionary[#"data"][#"items"][#"player"]["mobile"]];
}
#catch (NSException *exception) {
// handle exception
}

Resources