我是iOS和推送通知的新手。我的PNS在开发模式上工作得很好,现在我想用它来制作。
Plase指导我完成生产模式的所有程序。另外,我如何在生产模式下测试是否接收推送通知。??
Belo代码在开发模式下工作良好......
#pragma mark - Push Notifications Methods
- (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
NSString *tokenStr = [deviceToken description];
// Separete Your device token with <,< and blanksapace
NSString *pushToken = [[[tokenStr
stringByReplacingOccurrencesOfString:@"<" withString:@""]
stringByReplacingOccurrencesOfString:@">" withString:@""]
stringByReplacingOccurrencesOfString:@" " withString:@""];
sclass.deviceToken = pushToken;
// Save the token to server
NSString *urlStr = [NSString stringWithFormat:@"http://www.vijaywebsolutions.com/Development_FTP/webservice/webservices.php?deviceToken=%@",pushToken]; // Passing token to URL
NSURL *url = [NSURL URLWithString:urlStr];
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:req delegate:self]; // Support to perform URLrequest
if( theConnection )// checking connection successfull or not
{
webData = [NSMutableData data];
NSLog(@"device token is %@", pushToken);
}
}
- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo
{
if (application.applicationState == UIApplicationStateActive) // If app is running and you got notification then show it
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Did receive a Remote Notification" message:[NSString stringWithFormat:@"You Have a Notification :\n%@",userInfo[@"aps"][@"alert"]]delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
}
NSLog(@"Payload: %@", userInfo);
imageURL = userInfo[@"aps"][@"alert"];
MainViewController *MvC=[[MainViewController alloc]initWithNibName:@"MainViewControlleripad" bundle:nil];
self.window.rootViewController=MvC;
[MvC sshowansimage:imageURL];
}
答案 0 :(得分:2)
要测试生产推送通知服务,请在配置文件中为您的应用创建Adhoc分发配置文件。下载配置文件并安装。选择Adhoc dist配置文件以对您的应用进行代码签名。存档ipa并保存以进行adhoc分发。将ipa添加到您的设备并进行测试推送。它将使用生产推送证书而不是开发证书。
对于创建生产推送证书,您遵循与开发完全相同的过程,但您在apple dev门户中选择生产(而不是沙盒)证书。
答案 1 :(得分:2)
您需要分布式配置文件来测试产品模式。 产品 - &gt;档案 - &gt;分发 - &gt;保存企业或Ad hoc - &gt;然后选择分布式配置文件。然后安装ipa文件。 只有在iphone越狱时才能执行此操作。
如果没有,如果您通过了开发模式测试,则无需担心产品模式。只需将apns url替换为产品模式,并且都是正确的。