我已經爲我的應用程序設置了推送通知,以便當我單擊推送通知時,應用程序將轉到主控制視圖。但是,我想查看一個特定的視圖控制器,具體取決於我添加到我的應用程序的內容。我怎樣才能做到這一點?IOS 7通過單擊推送通知查看特定視圖控制器
我的應用程序委託代碼。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeNone)];
return YES;
}
-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
const char* data = [deviceToken bytes];
NSMutableString * token = [NSMutableString string];
for (int i = 0; i < [deviceToken length]; i++) {
[token appendFormat:@"%02.2hhX", data[i]];
}
NSString *urlString = [NSString stringWithFormat:@"url"?token=%@",token];
NSURL *url = [[NSURL alloc] initWithString:urlString];
NSLog(@"token %@",urlString);
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
NSLog(@"request %@ ",urlRequest);
NSData *urlData;
NSURLResponse *response;
urlData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:nil];
NSLog(@"data %@",urlData);
// NSLog(@"token ",sendUserToken);
}
我的PHP推送通知腳本。
<?php
token ="my token"
$payload = '{
"aps" :
{
"alert" :"'.$message.'",
"badge" : 1,
"sound" : "bingbong.aiff"
}
}';
$ctx = stream_context_create();
stream_context_set_option($ctx,'ssl', 'local_cert','ck.pem');
stream_context_set_option($ctx,'ssl','passphrase', 'balpad');
$fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195',$err,$errstr,60,STREAM_CLIENT_CONNECT,$ctx);
if(!fp){
print "Failed to connect $err $errstrn";
return;
}else{
print "notifications sent!";
}
$devArray = array();
$devArray[] = $deviceToken;
foreach($deviceToken as $token){
$msg = chr(0) . pack("n",32) . pack("H*", str_replace(' ',' ',$token)).pack("n",strlen($payload)) . $payload;
print "sending message:" .$payload . "n";
fwrite($fp,$msg);
}
fclose($fp);
}
?>
這第一次我使用推送通知,我還沒有發現這是一個妥善的解決辦法。我發現了一些建議(link1link2),但我覺得他們有點混亂,我沒有得到任何想法。請有人指導我如何做到這一點。
小心把太多的信息放到Push中,Apple可以拒絕它:( – Rambatino