vendredi 1 juillet 2016

Error code 405: while Uploading file(NSData) With NSURLSession with uploadTaskWithRequest

I am trying to upload file to server location which is like this :

urlString : http://uploads.myLocation.com

Its is coming up as status code 405 - which means "Method not allowed". Do I need PHP script as suggested on last answer of this link ? ios Upload Image and Text using HTTP POST

How do server understand what I am sending? Is it any work for me as an IOS developer or its server side issue?

class func uploadTask(urlString: String, withDataString : String) {

    print("URL To Upload :(urlString)")

    if let percentURL = urlString.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLQueryAllowedCharacterSet())
    {



    let url:NSURL = NSURL(string: percentURL)!
    let session = NSURLSession.sharedSession()

    let request = NSMutableURLRequest(URL: url)
    request.HTTPMethod = "POST"
    request.cachePolicy = NSURLRequestCachePolicy.ReloadIgnoringCacheData


        let data = withDataString.dataUsingEncoding(NSUTF8StringEncoding)


        print("Data Length :(data?.length)")

        let task = session.uploadTaskWithRequest(request, fromData: data, completionHandler:
        {

            (data,response,error) in

            if error == nil
            {
                print("Response :(response)")

                let httpResponse = response as! NSHTTPURLResponse

                let statusCode = httpResponse.statusCode

                print("Status Code: (statusCode)") 


            }
            else
            {
                print("Error Uploading Data :(error)")

            }



        }
    );

    task.resume()

}
}

Fabric - MoPub: No ads found for ad unit

I am currently developing an iOS app (could be Android or sth else, that's not the issue here) and have just included the MoPub kit through fabric in order to monetize the app through ads.

After implementing a full screen/interstitial ad with the test unit id, the interstitial shows perfectly. However, when using my personal ad unit ID, the ad doesn't show up. What I get from the console is the following:

MOPUB: Interstitial controller is loading ad with MoPub server URL: https://ads.mopub.com/m/ad?v=8&udid=ifa:XXXX&id=1234567890&nv=4.7.0&o=p&sc=2.0&z=+0100&mr=1&ct=2&av=1.5&cn=EE&iso=gb&mnc=30&mcc=234&dn=iPhone7%2C2&w=640&h=1136&bundle=com.company.appId
MOPUB: Interstitial ad view is fetching ad network type: clear
MOPUB: No ads found for ad unit: 1234567890

N.B: if I do the exact same process with the banner, no issues; for some reason I ignore, it only happens to me with the interstitial.

Does anyone know how to solve this issue?

android opencv - is it possible to catch a different click on 3D object per rotation?

I got a task to do in the Augmented Reality subject. I need to develop an android app with augmented reality, where i have an image target that i can scan with my camera, and i need to display a 3D object on it. Now the problem is this, let's say i have a 3D object of a cube. I need to have the ability to control the click of every side of my 3D cube. if i click on one side of the cube, i'll be able to do one thing, and if i click on another side of the cube, i'll be able to do another thing.

I'm using the ARToolkit framework which based on opencv. I'm using the AR simple project of the ARToolkit SDK, the source code i took from here:

https://github.com/kosiara/artoolkit-android-studio-example

The opencv libraries were made with c++.

hopefully you guys can help me, I've been searching for hours for a solution. I've searched for other frameworks, and tried doing it myself, but i had no success in this.

include headers to OpenCL .cl file

I've written an OpenCL kernel in a .cl file. It attempts to #include several headers.

Its compilation fails, since the included header files are "not found". I am aware that clBuildProgram can take the -I dir option, which adds the directory dir to the list of directories to be searched for the header files.

In the khronus site forum this post http://www.khronos.org/message_boards/viewtopic.php?f=37&t=2535 talks about the issue.

They propose to use clCreateProgramWithSource which specifies all sources (including .h files).

I have a questions regarding this issue:

  1. Which option is better? (clBuildProgram vs. clCreateProgramWithSource, as described above)
  2. If I use clCreateProgramWithSource how does the compiler know what to include? I mean, which source stands for which included file name?
  3. If I use clBuildProgram and there are several directories with include files, how do I specify them?

Memory footprint for the same number of objects

class A {};
class B {};
Both the classes are properly defined.

struct MyStruct{
typedef std::vector< std::pair< const A*, const B* > > TVec;
std::map< std::string, TVec > d_data;
};

Now i have a 2D array of 10X10 where each element of my 2D array is of type struct MyStruct.

Now i have 100 elements to add in this 2D array. If each element is inserted at unique position in array, in that case, my memory footprint is, let say 'X' MB. each 2D array element contains exactly one MyStruct element stored.

But if i add all the 100 elements of type MyStruct at last position i.e. 2DArr[9][9], my memory footprint is, let say 'Y' MB.

Assume that map size is 1 i.e. there is only 1 key and corresponding to that key, multiple values are stored in a vector.

What i see is, 'Y' is close to 4 times greater then 'X' Why it is as at the end, i am inserting same number of elements i.e. 100 MyStruct elements in the 2D array but at different locations in both the cases.

Core Data many to many through table with custom fields

My object model has article and media where articles reference media in a many to many relationship. The media may have different ordering and need to store the order of that media relative to the article, i,e, not on the media itself.

Core Data internally generates a sqlite database with the through table as:

article_id, media_id

Core Data/MagicalRecord objects are article and media:

class Article: NSManagedObject {
  ...
  @NSManaged var media: NSSet
}

class Media: NSManagedObject {
  ...
}

Is there a means in Core Data to persist the order of media in a through table mechanism? Instead I seem to need to create a new media record with its own position each time that media is used by an article.

In Django and Rails I make use of a through table in my model to store a position/order integer that says this media for this article is in this order. The table would have these columns:

article_id, media_id, position

It seems a through table with custom fields is not possible in Core Data?

zmq python publish c++ subscribe

I have a zmq publisher in c++ (using zhelpers.hpp) and zmq subscriber in python3 (using pyzmq). Trouble is, no message is recived in subscriber. I suppose, there is a problem with zmq filter. I cant figure out, how to properly use setsockopt in c++ to recive messages from python publisher.

Python publisher:

    import zmq
    context = zmq.Context()
    socket = context.socket(zmq.PUB)
    context = zmq.Context()
    socket = context.socket(zmq.PUB)
    socket.bind("tcp://*:4004")
    while True:
      command = input("insert command ")
      if (command=='c'):
            topic = "CALL".encode("ascii")
            data = "blabla".encode("ascii")
            socket.send_multipart([topic,data])

C++ subscriber:

    #include "zhelpers.hpp"
    zmq::context_t context(1);
    zmq::socket_t subscriber1 (context, ZMQ_SUB);
    subscriber1.connect("tcp://127.0.0.1:4004");
    subscriber1.setsockopt( ZMQ_SUBSCRIBE, "CALL", 4);
    while (1) {
        // read envelope
        std::string address = s_recv (subscriber1);
        // read message
        std::string contents = s_recv (subscriber1);
        std::cout << "[" << address << "] " << contents << std::endl;

Python subscriber is workking fine. Code:

    subscriber = context.socket(zmq.SUB)
    subscriber.connect("tcp://127.0.0.1:4004")
    subscriber.setsockopt(zmq.SUBSCRIBE, b"CALL")
    [command, contents] = self.subscriber.recv_multipart()