Bladeren bron

Modify for Json

Marino Faggiana 8 jaren geleden
bovenliggende
commit
9037d6350f

+ 13 - 5
Libraries external/OCCommunicationLib/OCCommunicationLib/OCCommunication.m

@@ -1297,13 +1297,21 @@
     [request getNotificationsOfTheServer:serverPath onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
         
         NSData *responseData = (NSData*) responseObject;
-        OCXMLNotificationsParser *parser = [[OCXMLNotificationsParser alloc] init];
-            
-        [parser initParserWithData:responseData];
-        NSMutableArray *notificationsList = [parser.notificationsList mutableCopy];
+        
+        //Parse
+        NSError *error;
+        NSDictionary *jsongParsed = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
+        NSLog(@"dic: %@",jsongParsed);
+        
+        OCNotifications *notification = [OCNotifications new];
+
+        
+        
+        
+        
     
         //Return success
-        successRequest(response, notificationsList, request.redirectedServer);
+        successRequest(response, notification, request.redirectedServer);
         
     } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
         failureRequest(response, error, request.redirectedServer);

+ 5 - 6
Libraries external/OCCommunicationLib/OCCommunicationLib/OCWebDavClient/OCWebDAVClient.m

@@ -622,14 +622,13 @@ NSString const *OCWebDAVModificationDateKey	= @"modificationdate";
 
 #pragma mark - Get Notification
 
-- (void) getNotificationsOfTheServer:(NSString *)serverPath
-                onCommunication:(OCCommunication *)sharedOCCommunication
-                        success:(void(^)(NSHTTPURLResponse *, id))success
-                        failure:(void(^)(NSHTTPURLResponse *, id  _Nullable responseObject, NSError *))failure {
-    
-    NSParameterAssert(success);
+- (void) getNotificationsOfTheServer:(NSString*)serverPath onCommunication:(OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *operation, id response))success
+                             failure:(void(^)(NSHTTPURLResponse *operation, id  _Nullable responseObject, NSError *error))failure{
     
     _requestMethod = @"GET";
+
+    NSString *jsonQuery = [NSString stringWithFormat:@"?format=json"];
+    serverPath = [serverPath stringByAppendingString:jsonQuery];
     
     NSMutableURLRequest *request = [self sharedRequestWithMethod:_requestMethod path:serverPath parameters:nil];
     

+ 0 - 27
Libraries external/OCCommunicationLib/OCCommunicationLib/OCXMLNotificationsParser.h

@@ -1,27 +0,0 @@
-//
-//  OCXMLNotificationsParser.h
-//  ownCloud iOS library
-//
-//  Created by Marino Faggiana on 23/01/17.
-//  Copyright © 2017 ownCloud. All rights reserved.
-//
-
-#import <Foundation/Foundation.h>
-#import "OCNotifications.h"
-
-@interface OCXMLNotificationsParser : NSObject <NSXMLParserDelegate> {
-
-    NSMutableString *_xmlChars;
-    NSMutableDictionary *_xmlBucket;
-    NSMutableArray *_notificationsList;
-    OCNotifications *_currentNotifications;
-    BOOL isNotFirstFileOfList;
-}
-
-@property(nonatomic,strong) NSMutableArray *notificationsList;
-@property(nonatomic,strong) OCNotifications *currentNotifications;
-
-- (void)initParserWithData: (NSData*)data;
-
-
-@end

+ 0 - 81
Libraries external/OCCommunicationLib/OCCommunicationLib/OCXMLNotificationsParser.m

@@ -1,81 +0,0 @@
-//
-//  OCXMLNotificationsParser.m
-//  ownCloud iOS library
-//
-//  Created by Marino Faggiana on 23/01/17.
-//  Copyright © 2017 ownCloud. All rights reserved.
-//
-
-#import "OCXMLNotificationsParser.h"
-
-@implementation OCXMLNotificationsParser
-
-@synthesize notificationsList =_notificationsList;
-@synthesize currentNotifications =_currentNotifications;
-
-
-/*
- * Method that init the parse with the xml data from the server
- * @data -> XML webDav data from the owncloud server
- */
-- (void)initParserWithData: (NSData*)data{
-    
-    _notificationsList = [[NSMutableArray alloc]init];
-    
-    NSXMLParser *parser = [[NSXMLParser alloc] initWithData:data];
-    [parser setDelegate:self];
-    [parser parse];
-}
-
-/*
- * Method that init parse process.
- */
-
-- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict {
-    
-    if (!_xmlChars) {
-        _xmlChars = [NSMutableString string];
-    }
-    
-    //NSLog(@"_xmlChars: %@", _xmlChars);
-    
-    [_xmlChars setString:@""];
-    
-    if ([elementName isEqualToString:@"d:response"]) {
-        _xmlBucket = [NSMutableDictionary dictionary];
-    }
-}
-
-/*
- * Util method to make a NSDate object from a string from xml
- * @dateString -> Data string from xml
- */
-+ (NSDate*)parseDateString:(NSString*)dateString {
-    //Parse the date in all the formats
-    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
-    /*In most cases the best locale to choose is "en_US_POSIX", a locale that's specifically designed to yield US English results regardless of both user and system preferences. "en_US_POSIX" is also invariant in time (if the US, at some point in the future, changes the way it formats dates, "en_US" will change to reflect the new behaviour, but "en_US_POSIX" will not). It will behave consistently for all users.*/
-    [dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]];
-    //This is the format for the concret locale used
-    [dateFormatter setDateFormat:@"EEE, dd MMM y HH:mm:ss zzz"];
-    
-    NSDate *theDate = nil;
-    NSError *error = nil;
-    if (![dateFormatter getObjectValue:&theDate forString:dateString range:nil error:&error]) {
-        NSLog(@"Date '%@' could not be parsed: %@", dateString, error);
-    }
-    
-    return theDate;
-}
-
-
-// Decode a percent escape encoded string.
-- (NSString*) decodeFromPercentEscapeString:(NSString *) string {
-    return (__bridge NSString *) CFURLCreateStringByReplacingPercentEscapesUsingEncoding(NULL,
-                                                                                         (__bridge CFStringRef) string,
-                                                                                         CFSTR(""),
-                                                                                         kCFStringEncodingUTF8);
-}
-
-
-
-@end

+ 0 - 6
Libraries external/OCCommunicationLib/ownCloud iOS library.xcodeproj/project.pbxproj

@@ -49,7 +49,6 @@
 		EAABAB3C185EE33B00909831 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EAABAB3B185EE33B00909831 /* UIKit.framework */; };
 		EAABAB40185F225300909831 /* video.MOV in Resources */ = {isa = PBXBuildFile; fileRef = EAABAB3F185F225300909831 /* video.MOV */; };
 		F71DB38D1E35FAD80057BEE3 /* OCNotifications.m in Sources */ = {isa = PBXBuildFile; fileRef = F71DB38C1E35FAD80057BEE3 /* OCNotifications.m */; };
-		F71DB3901E36111E0057BEE3 /* OCXMLNotificationsParser.m in Sources */ = {isa = PBXBuildFile; fileRef = F71DB38F1E36111E0057BEE3 /* OCXMLNotificationsParser.m */; };
 /* End PBXBuildFile section */
 
 /* Begin PBXContainerItemProxy section */
@@ -139,8 +138,6 @@
 		EAABAB3F185F225300909831 /* video.MOV */ = {isa = PBXFileReference; lastKnownFileType = video.quicktime; name = video.MOV; path = Resources/video.MOV; sourceTree = "<group>"; };
 		F71DB38B1E35FAD80057BEE3 /* OCNotifications.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OCNotifications.h; sourceTree = "<group>"; };
 		F71DB38C1E35FAD80057BEE3 /* OCNotifications.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OCNotifications.m; sourceTree = "<group>"; };
-		F71DB38E1E36111E0057BEE3 /* OCXMLNotificationsParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OCXMLNotificationsParser.h; sourceTree = "<group>"; };
-		F71DB38F1E36111E0057BEE3 /* OCXMLNotificationsParser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OCXMLNotificationsParser.m; sourceTree = "<group>"; };
 /* End PBXFileReference section */
 
 /* Begin PBXFrameworksBuildPhase section */
@@ -170,8 +167,6 @@
 		13AA8637187C331F00A10927 /* Parsers */ = {
 			isa = PBXGroup;
 			children = (
-				F71DB38E1E36111E0057BEE3 /* OCXMLNotificationsParser.h */,
-				F71DB38F1E36111E0057BEE3 /* OCXMLNotificationsParser.m */,
 				131C67B7187C3E360009030E /* OCXMLSharedParser.h */,
 				131C67B8187C3E360009030E /* OCXMLSharedParser.m */,
 				13AA863E187C3B9700A10927 /* OCXMLParser.h */,
@@ -441,7 +436,6 @@
 				131C67B9187C3E360009030E /* OCXMLSharedParser.m in Sources */,
 				13AA8640187C3B9700A10927 /* OCXMLParser.m in Sources */,
 				EA7CC912183E146000B6A4B4 /* UtilsFramework.m in Sources */,
-				F71DB3901E36111E0057BEE3 /* OCXMLNotificationsParser.m in Sources */,
 				EA7CC92A183E14A100B6A4B4 /* NSDate+RFC1123.m in Sources */,
 				13AA8636187C211900A10927 /* OCSharedDto.m in Sources */,
 				EA7CC928183E14A100B6A4B4 /* NSDate+ISO8601.m in Sources */,