Objective-C ile WhatsApp API Nasıl Gönderilir

Tanıtım

Bu eğitimde, Objective-C kullanarak WhatsApp API üzerinden mesaj göndermek için basit örnekler oluşturacağız.

Objective-C Kullanan İlk WhatsApp API Mesajı


#import <Foundation/Foundation.h>

NSDictionary *headers = @{ @"content-type": @"application/x-www-form-urlencoded" };

NSMutableData *postData = [[NSMutableData alloc] initWithData:[@"token=token_here" dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:[@"&to=1408XXXXXXX" dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:[@"&body=WhatsApp API on UltraMsg.com works good" dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:[@"&priority=10" dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:[@"&referenceId=" dataUsingEncoding:NSUTF8StringEncoding]];

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://api.ultramsg.com/instance1150/messages/chat"]
                                                       cachePolicy:NSURLRequestUseProtocolCachePolicy
                                                   timeoutInterval:10.0];
[request setHTTPMethod:@"POST"];
[request setAllHTTPHeaderFields:headers];
[request setHTTPBody:postData];

NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request
                                            completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
                                                if (error) {
                                                    NSLog(@"%@", error);
                                                } else {
                                                    NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
                                                    NSLog(@"%@", httpResponse);
                                                }
                                            }];
[dataTask resume];

Resim Gönder

#import <Foundation/Foundation.h>

NSDictionary *headers = @{ @"content-type": @"application/x-www-form-urlencoded" };

NSMutableData *postData = [[NSMutableData alloc] initWithData:[@"token=token_here" dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:[@"&to=1408XXXXXXX" dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:[@"&image=https://file-example.s3-accelerate.amazonaws.com/images/test.jpg" dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:[@"&caption=image Caption" dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:[@"&referenceId=" dataUsingEncoding:NSUTF8StringEncoding]];

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://api.ultramsg.com/instance1150/messages/image"]
                                                       cachePolicy:NSURLRequestUseProtocolCachePolicy
                                                   timeoutInterval:10.0];
[request setHTTPMethod:@"POST"];
[request setAllHTTPHeaderFields:headers];
[request setHTTPBody:postData];

NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request
                                            completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
                                                if (error) {
                                                    NSLog(@"%@", error);
                                                } else {
                                                    NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
                                                    NSLog(@"%@", httpResponse);
                                                }
                                            }];
[dataTask resume];

Belge Gönder

#import <Foundation/Foundation.h>

NSDictionary *headers = @{ @"content-type": @"application/x-www-form-urlencoded" };

NSMutableData *postData = [[NSMutableData alloc] initWithData:[@"token=token_here" dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:[@"&to=1408XXXXXXX" dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:[@"&filename=hello.pdf" dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:[@"&document=https://file-example.s3-accelerate.amazonaws.com/documents/cv.pdf" dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:[@"&referenceId=" dataUsingEncoding:NSUTF8StringEncoding]];

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://api.ultramsg.com/instance1150/messages/document"]
                                                       cachePolicy:NSURLRequestUseProtocolCachePolicy
                                                   timeoutInterval:10.0];
[request setHTTPMethod:@"POST"];
[request setAllHTTPHeaderFields:headers];
[request setHTTPBody:postData];

NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request
                                            completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
                                                if (error) {
                                                    NSLog(@"%@", error);
                                                } else {
                                                    NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
                                                    NSLog(@"%@", httpResponse);
                                                }
                                            }];
[dataTask resume];

Ses Gönder

#import <Foundation/Foundation.h>

NSDictionary *headers = @{ @"content-type": @"application/x-www-form-urlencoded" };

NSMutableData *postData = [[NSMutableData alloc] initWithData:[@"token=token_here" dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:[@"&to=1408XXXXXXX" dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:[@"&audio=https://file-example.s3-accelerate.amazonaws.com/audio/2.mp3" dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:[@"&referenceId=" dataUsingEncoding:NSUTF8StringEncoding]];

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://api.ultramsg.com/instance1150/messages/audio"]
                                                       cachePolicy:NSURLRequestUseProtocolCachePolicy
                                                   timeoutInterval:10.0];
[request setHTTPMethod:@"POST"];
[request setAllHTTPHeaderFields:headers];
[request setHTTPBody:postData];

NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request
                                            completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
                                                if (error) {
                                                    NSLog(@"%@", error);
                                                } else {
                                                    NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
                                                    NSLog(@"%@", httpResponse);
                                                }
                                            }];
[dataTask resume];

Ses Gönder

#import <Foundation/Foundation.h>

NSDictionary *headers = @{ @"content-type": @"application/x-www-form-urlencoded" };

NSMutableData *postData = [[NSMutableData alloc] initWithData:[@"token=token_here" dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:[@"&to=1408XXXXXXX" dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:[@"&audio=https://file-example.s3-accelerate.amazonaws.com/voice/oog_example.ogg" dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:[@"&referenceId=" dataUsingEncoding:NSUTF8StringEncoding]];

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://api.ultramsg.com/instance1150/messages/voice"]
                                                       cachePolicy:NSURLRequestUseProtocolCachePolicy
                                                   timeoutInterval:10.0];
[request setHTTPMethod:@"POST"];
[request setAllHTTPHeaderFields:headers];
[request setHTTPBody:postData];

NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request
                                            completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
                                                if (error) {
                                                    NSLog(@"%@", error);
                                                } else {
                                                    NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
                                                    NSLog(@"%@", httpResponse);
                                                }
                                            }];
[dataTask resume];

Video Gönder

#import <Foundation/Foundation.h>

NSDictionary *headers = @{ @"content-type": @"application/x-www-form-urlencoded" };

NSMutableData *postData = [[NSMutableData alloc] initWithData:[@"token=token_here" dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:[@"&to=1408XXXXXXX" dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:[@"&video=https://file-example.s3-accelerate.amazonaws.com/video/test.mp4" dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:[@"&referenceId=" dataUsingEncoding:NSUTF8StringEncoding]];

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://api.ultramsg.com/instance1150/messages/video"]
                                                       cachePolicy:NSURLRequestUseProtocolCachePolicy
                                                   timeoutInterval:10.0];
[request setHTTPMethod:@"POST"];
[request setAllHTTPHeaderFields:headers];
[request setHTTPBody:postData];

NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request
                                            completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
                                                if (error) {
                                                    NSLog(@"%@", error);
                                                } else {
                                                    NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
                                                    NSLog(@"%@", httpResponse);
                                                }
                                            }];
[dataTask resume];
#import <Foundation/Foundation.h>

NSDictionary *headers = @{ @"content-type": @"application/x-www-form-urlencoded" };

NSMutableData *postData = [[NSMutableData alloc] initWithData:[@"token=token_here" dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:[@"&to=1408XXXXXXX" dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:[@"&link=https://en.wikipedia.org/wiki/COVID-19" dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:[@"&referenceId=" dataUsingEncoding:NSUTF8StringEncoding]];

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://api.ultramsg.com/instance1150/messages/link"]
                                                       cachePolicy:NSURLRequestUseProtocolCachePolicy
                                                   timeoutInterval:10.0];
[request setHTTPMethod:@"POST"];
[request setAllHTTPHeaderFields:headers];
[request setHTTPBody:postData];

NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request
                                            completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
                                                if (error) {
                                                    NSLog(@"%@", error);
                                                } else {
                                                    NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
                                                    NSLog(@"%@", httpResponse);
                                                }
                                            }];
[dataTask resume];

Kişi Gönder

#import <Foundation/Foundation.h>

NSDictionary *headers = @{ @"content-type": @"application/x-www-form-urlencoded" };

NSMutableData *postData = [[NSMutableData alloc] initWithData:[@"token=token_here" dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:[@"&to=1408XXXXXXX" dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:[@"&[email protected]" dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:[@"&referenceId=" dataUsingEncoding:NSUTF8StringEncoding]];

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://api.ultramsg.com/instance1150/messages/contact"]
                                                       cachePolicy:NSURLRequestUseProtocolCachePolicy
                                                   timeoutInterval:10.0];
[request setHTTPMethod:@"POST"];
[request setAllHTTPHeaderFields:headers];
[request setHTTPBody:postData];

NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request
                                            completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
                                                if (error) {
                                                    NSLog(@"%@", error);
                                                } else {
                                                    NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
                                                    NSLog(@"%@", httpResponse);
                                                }
                                            }];
[dataTask resume];

Konum göndermek

#import <Foundation/Foundation.h>

NSDictionary *headers = @{ @"content-type": @"application/x-www-form-urlencoded" };

NSMutableData *postData = [[NSMutableData alloc] initWithData:[@"token=token_here" dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:[@"&to=1408XXXXXXX" dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:[@"&address=ABC company \n Sixth floor , office 38" dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:[@"&lat=25.197197" dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:[@"&lng=55.2721877" dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:[@"&referenceId=" dataUsingEncoding:NSUTF8StringEncoding]];

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://api.ultramsg.com/instance1150/messages/location"]
                                                       cachePolicy:NSURLRequestUseProtocolCachePolicy
                                                   timeoutInterval:10.0];
[request setHTTPMethod:@"POST"];
[request setAllHTTPHeaderFields:headers];
[request setHTTPBody:postData];

NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request
                                            completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
                                                if (error) {
                                                    NSLog(@"%@", error);
                                                } else {
                                                    NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
                                                    NSLog(@"%@", httpResponse);
                                                }
                                            }];
[dataTask resume];

Vcard gönder

#import <Foundation/Foundation.h>

NSDictionary *headers = @{ @"content-type": @"application/x-www-form-urlencoded" };

NSMutableData *postData = [[NSMutableData alloc] initWithData:[@"token=token_here" dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:[@"&to=1408XXXXXXX" dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:[@"&vcard= BEGIN:VCARD\nVERSION:3.0\nN:lastname;firstname\nFN:firstname lastname\nTEL;TYPE=CELL;waid=14000000001:14000000002\nNICKNAME:nickname\nBDAY:01.01.1987\nX-GENDER:M\nNOTE:note\nADR;TYPE=home:;;;;;;\nADR;TYPE=work_:;;;;;;\nEND:VCARD" dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:[@"&referenceId=" dataUsingEncoding:NSUTF8StringEncoding]];

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://api.ultramsg.com/instance1150/messages/vcard"]
                                                       cachePolicy:NSURLRequestUseProtocolCachePolicy
                                                   timeoutInterval:10.0];
[request setHTTPMethod:@"POST"];
[request setAllHTTPHeaderFields:headers];
[request setHTTPBody:postData];

NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request
                                            completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
                                                if (error) {
                                                    NSLog(@"%@", error);
                                                } else {
                                                    NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
                                                    NSLog(@"%@", httpResponse);
                                                }
                                            }];
[dataTask resume];

son olarak, Tam Whatsapp API Belgelerini ve SSS’yi görebilirsiniz.