iOS does not use third-party platforms to send push messages
4999 단어 iospushinformation
There are two points to pay attention to: one is to obtain DeviceToken in the code part, and look at the code
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//
UIRemoteNotificationType types =
(UIRemoteNotificationTypeBadge
|UIRemoteNotificationTypeSound
|UIRemoteNotificationTypeAlert);
//
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:types];
// Override point for customization after application launch.
return YES;
}
// DeviceToken
- (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
NSString *pushToken = [[[[deviceToken description]
stringByReplacingOccurrencesOfString:@"<" withString:@""]
stringByReplacingOccurrencesOfString:@">" withString:@""]
stringByReplacingOccurrencesOfString:@" " withString:@""] ;
NSLog(@"DeviceToken:%@",pushToken);
// , Device Token
}
Note: A little trick is used here, how to remove the "<",">",""in the NSData data content to get a valid DeviceToken.
//
- (void)application:(UIApplication *)application
didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
NSLog(@"Register Remote Notifications error:{%@}",[error localizedDescription]);
}
//
- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo
{
NSLog(@"Receive remote notification : %@",userInfo);
NSDictionary *aps = [userInfo valueForKey:@"aps"];
NSString *content = [aps valueForKey:@"alert"]; //
UIAlertView *alert =
[[UIAlertView alloc] initWithTitle:@" "
message:content
delegate:nil
cancelButtonTitle:@" "
otherButtonTitles:nil];
[alert show];
}
The second is to make a certificate with a push message
Enter the Apple development website:
Check with push service:
After the creation is successful, double-click the downloaded certificate, and you can see it in the keychain:
Right-click to export the p12 file, you can set a password, or you can not set it, generally do not set it. The above certificate is OK.
Let's take a look at the server code written in java:
package com.sdunicom.iphone.apns;
import javapns.back.PushNotificationManager;import javapns.back.SSLConnectionHelper;import javapns.data.Device;import javapns.data.PayLoad;
public class MainSend {public static void main(String[] args) throws Exception {try {String deviceToken = "56378f94d620b0210a9228ea513a4ba2cbe61d0b29143116812da411009c0c9e";
PayLoad payLoad = new PayLoad();payLoad.addAlert("Senkewei compatriots, everyone");payLoad.addBadge(1);//The number of message push tags, the number displayed in the small red circle. payLoad.addSound("default");PushNotificationManager pushManager = PushNotificationManager.getInstance();pushManager.addDevice("iPhone", deviceToken);//Connect to APNsString host= "gateway.sandbox.push.apple.com";int port = 2195;String certificatePath= "/Users/wangjinhan/Desktop/Recent Technical Research/java Background Pusher/developcm.p12";String certificatePassword= "";pushManager.initializeConnection(host,port, certificatePath,certificatePassword, SSLConnectionHelper.KEYSTORE_TYPE_PKCS12) ;//Send PushDevice client = pushManager.getDevice("iPhone");pushManager.sendNotification(client, payLoad);pushManager.stopConnection();
pushManager.removeDevice("iPhone");}catch (Exception e) {e.printStackTrace();}
}}
/************************
There are a few things to note about the code:
1. String deviceToken = "56378f94d620b0210a9228ea513a4ba2cbe61d0b29143116812da411009c0c9e";
to be sent to the corresponding device
2.payLoad.addBadge(1);
The number of message push tags, the number displayed in the small red circle. An accumulation is made on the server. When the click is clicked, it is counted, and if it is not viewed, it is accumulated all the time.
3.String certificatePath= "/Users/wangjinhan/Desktop/Recent technical research/java background push program/developcm.p12";
The path to the certificate, can't go wrong
4.String certificatePassword= "";
Export the password set by the certificate, no password is set, just as above
This can be pushed.
************************/
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Swift의 패스트 패스
Objective-C를 대체하기 위해 만들어졌지만 Xcode는 Objective-C 런타임 라이브러리를 사용하기 때문에 Swift와 함께 C, C++ 및 Objective-C를 컴파일할 수 있습니다.
Xcode는 S...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//
UIRemoteNotificationType types =
(UIRemoteNotificationTypeBadge
|UIRemoteNotificationTypeSound
|UIRemoteNotificationTypeAlert);
//
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:types];
// Override point for customization after application launch.
return YES;
}
// DeviceToken
- (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
NSString *pushToken = [[[[deviceToken description]
stringByReplacingOccurrencesOfString:@"<" withString:@""]
stringByReplacingOccurrencesOfString:@">" withString:@""]
stringByReplacingOccurrencesOfString:@" " withString:@""] ;
NSLog(@"DeviceToken:%@",pushToken);
// , Device Token
}
//
- (void)application:(UIApplication *)application
didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
NSLog(@"Register Remote Notifications error:{%@}",[error localizedDescription]);
}
//
- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo
{
NSLog(@"Receive remote notification : %@",userInfo);
NSDictionary *aps = [userInfo valueForKey:@"aps"];
NSString *content = [aps valueForKey:@"alert"]; //
UIAlertView *alert =
[[UIAlertView alloc] initWithTitle:@" "
message:content
delegate:nil
cancelButtonTitle:@" "
otherButtonTitles:nil];
[alert show];
}
Enter the Apple development website:
Check with push service:
After the creation is successful, double-click the downloaded certificate, and you can see it in the keychain:
Right-click to export the p12 file, you can set a password, or you can not set it, generally do not set it. The above certificate is OK.
Let's take a look at the server code written in java:
package com.sdunicom.iphone.apns;
import javapns.back.PushNotificationManager;import javapns.back.SSLConnectionHelper;import javapns.data.Device;import javapns.data.PayLoad;
public class MainSend {public static void main(String[] args) throws Exception {try {String deviceToken = "56378f94d620b0210a9228ea513a4ba2cbe61d0b29143116812da411009c0c9e";
PayLoad payLoad = new PayLoad();payLoad.addAlert("Senkewei compatriots, everyone");payLoad.addBadge(1);//The number of message push tags, the number displayed in the small red circle. payLoad.addSound("default");PushNotificationManager pushManager = PushNotificationManager.getInstance();pushManager.addDevice("iPhone", deviceToken);//Connect to APNsString host= "gateway.sandbox.push.apple.com";int port = 2195;String certificatePath= "/Users/wangjinhan/Desktop/Recent Technical Research/java Background Pusher/developcm.p12";String certificatePassword= "";pushManager.initializeConnection(host,port, certificatePath,certificatePassword, SSLConnectionHelper.KEYSTORE_TYPE_PKCS12) ;//Send PushDevice client = pushManager.getDevice("iPhone");pushManager.sendNotification(client, payLoad);pushManager.stopConnection();
pushManager.removeDevice("iPhone");}catch (Exception e) {e.printStackTrace();}
}}
/************************
There are a few things to note about the code:
1. String deviceToken = "56378f94d620b0210a9228ea513a4ba2cbe61d0b29143116812da411009c0c9e";
to be sent to the corresponding device
2.payLoad.addBadge(1);
The number of message push tags, the number displayed in the small red circle. An accumulation is made on the server. When the click is clicked, it is counted, and if it is not viewed, it is accumulated all the time.
3.String certificatePath= "/Users/wangjinhan/Desktop/Recent technical research/java background push program/developcm.p12";
The path to the certificate, can't go wrong
4.String certificatePassword= "";
Export the password set by the certificate, no password is set, just as above
This can be pushed.
************************/
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Swift의 패스트 패스
Objective-C를 대체하기 위해 만들어졌지만 Xcode는 Objective-C 런타임 라이브러리를 사용하기 때문에 Swift와 함께 C, C++ 및 Objective-C를 컴파일할 수 있습니다.
Xcode는 S...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Swift의 패스트 패스Objective-C를 대체하기 위해 만들어졌지만 Xcode는 Objective-C 런타임 라이브러리를 사용하기 때문에 Swift와 함께 C, C++ 및 Objective-C를 컴파일할 수 있습니다. Xcode는 S...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.